これは非常に基本的なことですが、明らかにエラーがない場合に修正する方法がわかりません。ありがとう
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/')