import os, 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('myfiles.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:\\'):
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\
print 'Found file in: ' + str(root)
shutil.copy(os.path.abspath(root + '/' + _file), 'C:\\NewPath\\')
自分自身を知ろうとせずに「どうすればこれを行うことができるか」と尋ねることによって、優れたプログラマーになることを学ぶことはできません。私は通常、問題を平和に分解することを人々に勧めます..
- Google: ディレクトリ内の Python リスト ファイル
- サンプルコードをいじって、何が最適かを確認してください
次に進みます。
- Google: Python コピー ファイル
- 事前に作成されたパスをいじって、ロジックが機能するかどうかを確認します
次に、両方を組み合わせます。