import os, re, shutil, sys, time
if len(sys.argv) == 1 or len(sys.argv) == 2:
exit()
#lst_file = 'list2.txt'
#search_dir = "./dir"
else:
lst_file = sys.argv[1]
search_dir = sys.argv[2]
start = time.time()
tag_dir = os.path.expandvars('$HOME') + "/Desktop/tmp/"
#讀取檔案清單並存放在 dict
dict = {}
with open(lst_file) as f:
for line in f.readlines():
line = line[:-1]
dict[line] = 0
#print "-----print dict list-----"
#print(dict.items())
#print
num_files = 0
#測試目標目錄是否存在,不在就建立目錄
if not os.path.isdir(tag_dir):
os.mkdir(tag_dir)
#遞迴目錄
for dirPath, dirNames, fileNames in os.walk(search_dir):
for f in fileNames:
num_files += 1
#print os.path.join(dirPath, f)
#strlst = re.findall(r"\d{6,13}", f)
#substr = "".join(strlst)
basename = os.path.splitext(f)[0]
if basename in dict:
print "finded >>", os.path.join(dirPath, f)
old = os.path.join(dirPath, f)
new = tag_dir + f
shutil.copy(old, new)
print "Total search files:", num_files
end = time.time()
print "Elapsed time:", end - start
aW1wb3J0IG9zLCByZSwgc2h1dGlsLCBzeXMsIHRpbWUKCmlmIGxlbihzeXMuYXJndikgPT0gMSBvciBsZW4oc3lzLmFyZ3YpID09IDI6CiAgICBleGl0KCkKICAgICNsc3RfZmlsZSA9ICdsaXN0Mi50eHQnCiAgICAjc2VhcmNoX2RpciA9ICIuL2RpciIKZWxzZToKICAgIGxzdF9maWxlID0gc3lzLmFyZ3ZbMV0KICAgIHNlYXJjaF9kaXIgPSBzeXMuYXJndlsyXQoKc3RhcnQgPSB0aW1lLnRpbWUoKQp0YWdfZGlyID0gb3MucGF0aC5leHBhbmR2YXJzKCckSE9NRScpICsgIi9EZXNrdG9wL3RtcC8iCiPoroDlj5bmqpTmoYjmuIXllq7kuKblrZjmlL7lnKggZGljdApkaWN0ID0ge30Kd2l0aCBvcGVuKGxzdF9maWxlKSBhcyBmOgogICAgZm9yIGxpbmUgaW4gZi5yZWFkbGluZXMoKToKICAgICAgICBsaW5lID0gbGluZVs6LTFdCi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