1 Star 0 Fork 0

xuscode/python-project

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
move_files.py 886 Bytes
一键复制 编辑 原始数据 按行查看 历史
terrycode 提交于 2024-06-25 12:35 +08:00 . 2024/06/25 周二 12:35:53.09
import os
import shutil
def copy_files_without_folders(source_dir, target_dir):
# 确保目标目录存在
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# 遍历源目录及其子目录
for root, dirs, files in os.walk(source_dir):
for file in files:
# 构造源文件的完整路径
file_path = os.path.join(root, file)
# 构造目标文件的路径,直接放在目标目录的根目录下
target_file_path = os.path.join(target_dir, file)
# 复制文件
shutil.copy2(file_path, target_file_path)
print(f"Copied: {file_path} to {target_file_path}")
source_directory = 'D:\\DS-Partner_Portal_CPE-EPP\\'
target_directory = 'D:\\DS-CHINA_Knowledge_sharing_&_training_Records\\DS-VIDEO\\'
copy_files_without_folders(source_directory, target_directory)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xuscode/python-project.git
git@gitee.com:xuscode/python-project.git
xuscode
python-project
python-project
master

搜索帮助