简体   繁体   中英

Error while move files using shutil.move() in python

I am trying to move files using shut.move().....But if the file is already existing at destination ...it will raise an exception.. But I want to move the file to destination forcibly. How can I achieve this?

You could use shutil.copy() which will overwrite the file.

https://docs.python.org/2/library/shutil.html#shutil.copy

EDIT

You could first remove the file in the destination directory with os.remove() and then use shutil.move() to move the file into the destination directory.

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