简体   繁体   中英

Rename and move the file to folder using shutil.move

def safe_copy(self,src,out_dir):
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    name = os.path.basename(src) 
    shutil.move(src,os.path.join(out_dir,'{}'.format(append_timestamp(name))))


safe_copy("\\\\server\\drive\\folder\\filename","\\\\server\\drive\\folder2")

I have the above function to move the file from source folder to destination folder. This function is working but the file is moving without the file extension and the file became unsupported.

Can anyone please advise me on this issue.

def safe_copy(src,out_dir):
   if not os.path.exists(out_dir):
     os.makedirs(out_dir)
   name = os.path.basename(src)
   shutil.move(src,os.path.join(out_dir,'{}'.format(append_timestamp(name))  + "." + src.split(".")[-1]))

If you are using this move method. You need to add the extension in src file.

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