简体   繁体   中英

Python - OSError: [WinError 17] The system cannot move the file to a different disk drive:

I'm using

os.rename()

to try to move pdf files between drives. Attempting this I receive the error:

OSError: [WinError 17] The system cannot move the file to a different disk drive

Is anyone aware of a function which contains similar functionality to os.rename and allows for across disk file transfer?

os.rename() change the path of the file but doesn't move its actual data on the disk. this is why you can't move (rename) it from one drive to another.

moving between drives is actually copy it first, and then delete the source file. you can use shutil.move() method which do it when you trying to transfer files between two drives

import shutil
shutil.move(src,dest)

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