0
只是想知道如果任何人有我如何才能优化我的简单而缓慢的文件替换脚本一个建议:优化简单的Python文件匹配和替换脚本
def switchFiles(args):
for root1, dirs1, files1 in os.walk(args.folder):
for f1 in files1:
for root2, dirs2, files2 in os.walk(args.database):
for f2 in files2:
if fnmatch.fnmatch(f1, f2):
command = 'cp '+os.path.join(root1, f1)+' '+os.path.join(root2, f2)
print(command)
os.system(command)
谢谢!
Cache'files2'并使用'shutil.copy()'而不是运行'cp'。 – Blender 2012-03-12 17:29:42
为什么使用'fnmatch.fnmatch'来比较两个简单的字符串?我错过了什么吗? – 2012-03-12 17:30:30
感谢搅拌机。大卫,我认为这种情况只是早期尝试的碎片。将改为==,并感谢您指出。 – barnhillec 2012-03-12 17:33:27