简体   繁体   中英

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. I'd like for the function do that, but also preserve the files in the source folder. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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