import os
import shutil
import copy
import pathlib
source_path = os.path.abspath(r’G:\ruijin\AD128~’)
source_path = os.path.abspath(r’C:\Users\86191\Desktop\beifen’)
target_path = os.path.abspath(r’E:\ruijinbold’)
filelist = os.listdir(source_path);
for files in filelist:
final_source_path = os.path.join(source_path, files) # 源文件
final_target_path = os.path.join(target_path, files) # 目标文件
if os.path.exists(final_target_path):
# 如果目标路径存在原文件夹的话就先删除
shutil.rmtree(final_target_path)
if not os.path.exists(final_target_path):
# 如果目标路径不存在原文件夹的话就创建
os.makedirs(final_target_path)
key1 = 'BOLD'
key2 = 'MPRAGE_AV'
for file in os.listdir(final_source_path):
# is file
# if os.path.isfile(file1 + '/' + file):
if key1 in file:
print('找到包含"' + key1 + '"字符的文件,绝对路径为----->' + final_source_path + '\\' + file)

本文介绍了一个使用Python实现的文件复制脚本,该脚本能够从指定的源目录中查找并复制包含特定关键字的文件到目标目录。通过遍历源目录下的所有文件,脚本检查每个文件名是否包含预设的关键字'BOLD'或'MPRAGE_AV',若匹配则将文件复制到目标目录下对应的位置。
最低0.47元/天 解锁文章
2747

被折叠的 条评论
为什么被折叠?



