简体   繁体   English

在python中使用shutil.move()移动文件时出错

[英]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. 我试图使用shut.move()移动文件.....但如果文件已经存在于目的地...它将引发异常..但我想强行将文件移动到目标。 How can I achieve this? 我怎样才能做到这一点?

You could use shutil.copy() which will overwrite the file. 您可以使用shutil.copy()来覆盖该文件。

https://docs.python.org/2/library/shutil.html#shutil.copy 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. 你可以先用删除文件在目标目录os.remove()然后使用shutil.move()将文件移动到目标目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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