当前位置: 首页 > wzjs >正文

商城小程序多少钱太原seo全网营销

商城小程序多少钱,太原seo全网营销,关于推进网站集约化建设的讲话,湖北专业网站建设质量保障c和python复制java文件到指定目录 ​​1.递归遍历目录​​ 2.​扁平化复制到目标目录​​ 快速收集分散在多个子目录中的 .java 文件到一个统一目录。 备份或简单迁移Java项目文件(无需保留目录结构时)。 该代码是一个实用的Java文件收集工具&#xff0c…

c++和python复制java文件到指定目录
​​1.递归遍历目录​​
2.​扁平化复制到目标目录​​
快速收集分散在多个子目录中的 .java 文件到一个统一目录。
备份或简单迁移Java项目文件(无需保留目录结构时)。
该代码是一个实用的Java文件收集工具,适合需要快速提取所有Java文件但无需考虑目录结构的场景,使用者需注意可能存在的文件覆盖问题。

step1:

输入路径:C:\Users\wangrusheng\Downloads\Dousheng-master
输出路径:C:\JavaFilesCopyz

step2:c++
C:\Users\wangrusheng\source\repos\CMakeProject1\CMakeProject1\CMakeProject1.cpp

#include <filesystem>
#include <iostream>
#include <string>namespace fs = std::filesystem;void copy_java_files(const std::string& source_dir, const std::string& dest_dir) {try {fs::path source_path(source_dir);fs::path dest_path(dest_dir);// 创建目标根目录fs::create_directories(dest_path);// 递归遍历源目录for (const auto& entry : fs::recursive_directory_iterator(source_path)) {if (entry.is_regular_file() && entry.path().extension() == ".java") {// 直接使用文件名作为目标路径fs::path full_dest_path = dest_path / entry.path().filename();// 复制文件(覆盖已存在的)fs::copy_file(entry.path(),full_dest_path,fs::copy_options::overwrite_existing);std::cout << "已复制: " << entry.path().filename() << std::endl;}}}catch (const fs::filesystem_error& e) {std::cerr << "文件操作错误: " << e.what() << std::endl;}catch (const std::exception& e) {std::cerr << "标准异常: " << e.what() << std::endl;}catch (...) {std::cerr << "未知错误发生" << std::endl;}
}int main() {copy_java_files(R"(C:\Users\wangrusheng\Downloads\Dousheng-master)",R"(C:\JavaFilesCopys)");return 0;
}

step3:python
C:\Users\wangrusheng\PycharmProjects\FastAPIProject1\hello.py

import os
import shutil
from pathlib import Pathdef copy_java_files(source_dir: str, dest_dir: str) -> None:try:# 创建目标目录Path(dest_dir).mkdir(parents=True, exist_ok=True)# 递归遍历源目录for root, _, files in os.walk(source_dir):for file in files:if file.endswith('.java'):src_path = os.path.join(root, file)dest_path = os.path.join(dest_dir, file)# 复制文件(自动覆盖)shutil.copy2(src_path, dest_path)print(f"已复制: {file}")except PermissionError as e:print(f"权限错误: {str(e)}")except OSError as e:print(f"操作系统错误: {str(e)}")except Exception as e:print(f"未知错误: {str(e)}")if __name__ == "__main__":source = r"C:\Users\wangrusheng\Downloads\Dousheng-master"destination = r"C:\JavaFilesCopyz"copy_java_files(source, destination)

step4:复制文件内容

#include <iostream>
#include <filesystem>
#include <fstream>
#include <string>
#include <algorithm>namespace fs = std::filesystem;int main() {// 定义目标目录和输出文件路径fs::path target_dir = "C:/Users/wangrusheng/Downloads/UnoGame-main/JavaFilesCopyz";fs::path output_file = target_dir / "java_files_content.txt";// 创建并打开输出文件std::ofstream outfile(output_file);if (!outfile.is_open()) {std::cerr << "错误:无法创建输出文件!" << std::endl;return 1;}try {// 遍历目标目录for (const auto& entry : fs::directory_iterator(target_dir)) {if (entry.is_regular_file()) {// 获取文件扩展名并转换为小写std::string ext = entry.path().extension().string();std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);// 判断是否为Java文件if (ext == ".java") {std::ifstream infile(entry.path());if (infile) {// 添加文件分隔标识outfile << "=== File: " << entry.path().filename().string()<< " ===\n";// 写入文件内容outfile << infile.rdbuf() << "\n\n";infile.close();}else {std::cerr << "警告:无法读取文件 "<< entry.path() << std::endl;}}}}}catch (const fs::filesystem_error& e) {std::cerr << "文件系统错误: " << e.what() << std::endl;return 1;}std::cout << "成功合并所有Java文件内容到:" << output_file << std::endl;return 0;
}

step5:功能整合,完成版

#include <filesystem>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>namespace fs = std::filesystem;// 复制所有Java文件到目标目录
void copy_java_files(const std::string& source_dir, const std::string& dest_dir) {try {fs::path source_path(source_dir);fs::path dest_path(dest_dir);fs::create_directories(dest_path); // 确保目标目录存在for (const auto& entry : fs::recursive_directory_iterator(source_path)) {if (entry.is_regular_file() && entry.path().extension() == ".java") {fs::path full_dest_path = dest_path / entry.path().filename();fs::copy_file(entry.path(), full_dest_path, fs::copy_options::overwrite_existing);std::cout << "已复制: " << entry.path().filename() << std::endl;}}}catch (const fs::filesystem_error& e) {std::cerr << "文件操作错误: " << e.what() << std::endl;}catch (const std::exception& e) {std::cerr << "标准异常: " << e.what() << std::endl;}catch (...) {std::cerr << "未知错误发生" << std::endl;}
}// 合并Java文件内容到文本文件
void merge_java_files(const std::string& target_dir, const std::string& output_filename) {try {fs::path output_path = fs::path(target_dir) / output_filename;std::ofstream outfile(output_path);if (!outfile.is_open()) {std::cerr << "错误:无法创建输出文件!" << std::endl;return;}for (const auto& entry : fs::directory_iterator(target_dir)) {if (entry.is_regular_file()) {std::string ext = entry.path().extension().string();std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);if (ext == ".java") {std::ifstream infile(entry.path());if (infile) {outfile << "=== File: " << entry.path().filename().string() << " ===\n";outfile << infile.rdbuf() << "\n\n";infile.close();}else {std::cerr << "警告:无法读取文件 " << entry.path() << std::endl;}}}}std::cout << "成功合并所有Java文件内容到:" << output_path << std::endl;}catch (const fs::filesystem_error& e) {std::cerr << "文件系统错误: " << e.what() << std::endl;}catch (const std::exception& e) {std::cerr << "标准异常: " << e.what() << std::endl;}catch (...) {std::cerr << "未知错误发生" << std::endl;}
}int main() {const std::string source_dir = R"(C:\Users\wangrusheng\Downloads\Dousheng-master)";const std::string dest_dir = R"(C:\JavaFilesCopyx)";const std::string output_filename = "java_files_content.txt";// 第一步:复制Java文件copy_java_files(source_dir, dest_dir);// 第二步:合并文件内容merge_java_files(dest_dir, output_filename);return 0;
}

step6:python版本

import os
import shutil
from pathlib import Pathdef copy_java_files(source_dir: str, dest_dir: str) -> None:try:source_path = Path(source_dir)dest_path = Path(dest_dir)# 确保目标目录存在os.makedirs(dest_path, exist_ok=True)# 递归查找所有Java文件for java_file in source_path.rglob('*.java'):dest_file = dest_path / java_file.name# 复制并覆盖已存在的文件shutil.copy2(java_file, dest_file)print(f"已复制: {java_file.name}")except OSError as e:print(f"文件操作错误: {e}")except Exception as e:print(f"标准异常: {e}")except:print("未知错误发生")def merge_java_files(target_dir: str, output_filename: str) -> None:try:target_path = Path(target_dir)output_path = target_path / output_filenamewith open(output_path, 'w', encoding='utf-8') as outfile:# 遍历目标目录下的文件for entry in target_path.iterdir():if entry.is_file() and entry.suffix.lower() == '.java':try:with open(entry, 'r', encoding='utf-8') as infile:content = infile.read()outfile.write(f"=== File: {entry.name} ===\n")outfile.write(content + "\n\n")except OSError as e:print(f"警告:无法读取文件 {entry.name}: {e}")except Exception as e:print(f"处理文件 {entry.name} 时发生异常: {e}")print(f"成功合并所有Java文件内容到:{output_path}")except OSError as e:print(f"文件系统错误: {e}")except Exception as e:print(f"标准异常: {e}")except:print("未知错误发生")def main():source_dir = r"C:\Users\wangrusheng\Downloads\Dousheng-master"dest_dir = r"C:\JavaFilesCopyw"output_filename = "java_files_content.txt"copy_java_files(source_dir, dest_dir)merge_java_files(dest_dir, output_filename)if __name__ == "__main__":main()

end

http://www.dtcms.com/wzjs/35446.html

相关文章:

  • 如何接单做网站关键词代发排名
  • 国外网站都不能上怎么做跨境电商百度推广是什么
  • 山东华建建设有限公司网站seo常用分析的专业工具
  • 安徽餐饮加盟网站建设无锡网站制作优化
  • 网站 功能需求百度手机app
  • 宝塔面板怎么做网站营销推广费用预算表
  • 网站要去公安局备案吗营销比较好的知名公司有哪些
  • 锦州哪里做网站品牌营销推广策划方案
  • 菏泽财富中心网站建设网络营销的方式与手段
  • wordpress建站公司国外免费域名
  • 我公司是做网站开发的怎么纳税网络营销外包公司
  • 网站建设与设计大作业苏州关键词seo排名
  • 嘉定网站建设公司百度广告推广收费标准
  • 鹰潭手机网站建设seo自动优化工具
  • 优酷 做视频网站还能成功吗济南seo小黑seo
  • 沈阳百度网站排名百度推广点击一次多少钱
  • 自己做家具展示网站百度站长平台网址
  • 帮人家做家务的网站网络营销案例分析ppt
  • wordpress重新安装数据库小红书seo排名
  • 投标网站建设服务承诺购买链接怎么买
  • 动态网站建设毕业设计方案手机优化大师怎么退款
  • 静态网站怎么更新网店运营培训哪里好
  • 锦州网站优化开封网络推广公司
  • 网站维护更新费用东莞网站推广公司黄页
  • 厦门网站制windows优化大师是什么软件
  • 免费模板下载网站推荐免费网站怎么申请
  • 哪个网站可以做论文简述百度关键字搜索量查询
  • 网站左侧悬浮如何建立网站平台的步骤
  • 聊城建网站服务西安疫情最新消息1小时内
  • 搭建个人小型服务器百度sem优化师