just wondering if anyone has a suggestion for how I can optimize my simple but slow file replacement script:
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)
Thanks!
This is a clean up code:
if args.folder and args.database are separate (not subdir), and all file’s name in their dir are unique, then you can do this: