[我写了一个简短的脚本,我想将所有.CR2文件(在下一步中,我要在前两个文件或第6个文件之间进行选择)移动到一个文件夹,该文件夹之前已作为raw_input创建。
import os
from os import path
import shutil
import itertools
proname = raw_input("Please Name the Productfolder: ")
path = "/Volumes/01_Produktfotos/_2020-01-JANUAR/"
os.mkdir(proname)
os.chdir(proname)
os.makedirs('_final')
os.makedirs('_images')
os.makedirs('_psd')
sourcepath = '/Volumes/01_Produktfotos/_2020-01-JANUAR/03.01/'
sourcefiles = os.listdir(sourcepath)
destinationpath = '/Volumes/01_Produktfotos/_2020-01-JANUAR/03.01/%proname/_images/'
for file in sourcefiles:
if file.endswith('.CR2'):
shutil.move(os.path.join(sourcepath,file), os.path.join(destinationpath,file))
此刻,脚本创建了用户特定的文件夹(名称),并在其中生成了子文件夹_images,_final和_psd。
我的问题是,它不会从用户创建的文件夹的顶部文件夹移动文件。
完美的结果是,如果
欢迎任何帮助或提示(:
预先感谢
与doc中一样,dst
是目录,而不是文件。
shutil.move(src,dst)递归将文件或目录(src)移至另一个位置(dst)。如果目标是现有目录,则将src移动到该目录内。如果目标已经存在但不是目录,则可能会根据os.rename()的语义将其覆盖。
# Before:
shutil.move(os.path.join(sourcepath,file), os.path.join(destinationpath,file))
# After:
shutil.move(os.path.join(sourcepath,file), destinationpath))
将起作用。