我知道这是非常基本的,但是当显然没有错误时我不知道如何修复它。谢谢
import os
import shutil
# First, create a list and populate it with the files
# you want to find (1 file per row in myfiles.txt)
files_to_find = []
with open('C:/Users/me/Desktop/test/_FileList.txt') as fh:
for row in fh:
files_to_find.append(row.strip)
# Then we recursively traverse through each folder
# and match each file against our list of files to find.
for root, dirs, files in os.walk('C:/Users/me/Desktop/test/newfolder'):
for _file in files:
if _file in files_to_find:
# If we find it, notify us about it and copy it it to C:\NewPath\
shutil.copy(os.path.abspath(root + '/' + _file), 'C:/Users/me/Desktop/test/')