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\\')
Run Code Online (Sandbox Code Playgroud)
通过询问"我如何做到这一点"而不试图找出自己,你永远不会学会成为一名优秀的程序员.我通常建议人们把这个问题打破平静.
然后继续前进
然后将它们结合起来.
| 归档时间: |
|
| 查看次数: |
4693 次 |
| 最近记录: |