簡體   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

此 function 從源文件夾中獲取 pdf/pptx 文件並將其放置在目標文件夾中。 我希望 function 這樣做,但也要保留源文件夾中的文件。 此外,如果文件已經存在於目標文件夾中,他們是否可以通過編程方式將新文件保存在現有文件之上?

#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\\')

您可以為此使用shutil.copy() 它將文件從源復制到目標,並將原始文件保留在源中。 我還相信,如果目標中已經有一個具有該名稱的文件,它將用您正在復制的文件覆蓋該文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM