当前位置: 首页 > 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/310522.html

相关文章:

  • 做网站挂广告免费网站推广优化
  • 政府网站建设方案书怎么做优化关键词
  • 公司网站开发费用入哪个科目批量查询权重
  • 苏州城乡建设局的网站首页谷歌搜索引擎入口363
  • 重庆网站制作团队杭州seo排名公司
  • 关于网站开发所需的知识推广公司产品
  • 特色网站模板站长统计 网站统计
  • 阿里巴巴官方网站互联网搜索引擎
  • wordpress comment_form_after王通seo赚钱培训
  • 免费网站收录中国北京出啥大事了
  • 网站建设流程步骤怎么样佛山旺道seo优化
  • 网站登录接口怎么做关键词排名快照优化
  • 沈阳世纪兴网站建设微商已经被国家定为传销了
  • 99到家网站怎么做网络推广项目计划书
  • 网站 后台 数据 下载站长之家素材网
  • 网站的优点缺点公众号代运营
  • 淮北网站建设推广百度公司注册地址在哪里
  • wordpress 健身预约沧州网站seo
  • 专业网页网站设计图书南宁百度seo优化
  • 建湖做网站资源优化网站排名
  • 深圳有做公司网站深圳网站优化网站
  • 网站建设的一般过程网页设计用什么软件
  • 做传销一般是不是有网站企业品牌推广网站
  • 建设银行信用卡卡网站首页线下推广
  • 建设 信用中国 网站制作网页模板
  • 河北省建设执业资格中心网站seo怎么发外链的
  • 网站用空间还是服务器关键词录入榜
  • 布谷海南网站建设免费二级域名注册网站
  • 院系网站建设宁德市古田县
  • win10电脑做网站怀化网络推广