我該如何改進這個python代碼。我想在這裏添加一個包含所有擴展名的列表,並且在列表的幫助下,我想搜索「src」擴展名目錄並將它們移動到目的地。基於擴展名的python移動文件?
import shutil
import glob
import os
dest_dir = "/home/xxxx/Software/"
dest_dir2 = "/home/flyingpizza/Pictures/"
for file in glob.glob(r'/home/xxxxx/Downloads/*.pdf'):
print (file)
shutil.move(file,dest_dir)
for file in glob.glob(r'/home/xxxx/Downloads/*.docx'):
print(file)
shutil.move(file, dest_dir)
for file in glob.glob(r'/home/xxxx/Downloads/*.exe'):
print(file)
shutil.move(file,dest_dir)
for file in glob.glob(r'/home/xxxx/Downloads/*.jpg'):
print(file)
shutil.move(file,dest_dir2)
for file in glob.glob(r'/home/xxxxx/Downloads/*.torrent'):
print(file)
os.remove(file)
也許加上'從頂部__future__進口print_function',所以這段代碼確實有效的標記中的python-2.7 ;-) – Dilettant