简体   繁体   English

使用 shutil.move(),我如何将文件移动到目标文件夹并同时将文件保留在源文件夹中

[英]Using shutil.move(), how do i move the file to destination folder and keep the file in the source folder at the same time

this function takes the pdf/pptx file from the source folder and places it in destination folder.此 function 从源文件夹中获取 pdf/pptx 文件并将其放置在目标文件夹中。 I'd like for the function do that, but also preserve the files in the source folder.我希望 function 这样做,但也要保留源文件夹中的文件。 Also, if the file already exists in the destination folder, is their a way to programatically save the new file over the existing file?此外,如果文件已经存在于目标文件夹中,他们是否可以通过编程方式将新文件保存在现有文件之上?

#function to place files in their respective folders once we know that all clientIDs are accounted for
def placeFiles():  
    for a, p in zip(clientInventory, folderName):
        shutil.move(source + quarter + str(a) + '.pdf', destination + str(p) + '\\' + str(a) + ' Performance\\')
        shutil.move(source + quarter + str(a) + '.pptx', destination + str(p) + '\\' + str(a) + ' Performance\\')

You can use shutil.copy() for this.您可以为此使用shutil.copy() It will copy the file from the source to the destination and keep the original in the source.它将文件从源复制到目标,并将原始文件保留在源中。 I believe also that if there is already a file in the destination with that name, it will overwrite the file with the one you are copying.我还相信,如果目标中已经有一个具有该名称的文件,它将用您正在复制的文件覆盖该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM