我正在尝试在 Windows 中移动我的文件。目前这些文件位于驱动器 C: 下的文件夹中,但我想将它们移动到 D: 中的某个位置。
我正在使用 shutil.move 函数,但该函数会覆盖文件(如果存在)。我想在目的地保留文件的副本而不是覆盖它。有这样做的功能吗?
def movefiles(strsrc, strdest, strextension):
filelistsrc = [] #source files full path
# store the destination of the current file
dictfiles = {}
for f in os.listdir(strsrc):
if os.path.isfile(os.path.join(strsrc, f)):
filefullname = os.path.join(strsrc, f)
if filefullname.endswith(".html"):
filelistsrc.append(filefullname)
dictfiles[filefullname] = os.path.join(strdest, f)
if not filelistsrc:
return -1
print("Start moving files from:")
printstrlist(filelistsrc)
for filename in filelistsrc:
shutil.move(filename, dictfiles[filename])
return 0
慕尼黑8549860
翻阅古今
喵喵时光机
相关分类