关于Python的拷贝文件用另一个方法

Copying a file with another name

本问题已经有最佳答案,请猛点这里访问。

我想把/local/mnt/workspace/user/Automation/swbuild/board/test_new.html复制成/local/mnt/workspace/user/Automation/sw_admin/reports/board/test.html,如果已经存在,就重写test.html。有内置的python copy命令吗?

1
2
/local/mnt/workspace/user/Automation/swbuild/board/test_new.html
/local/mnt/workspace/user/Automation/sw_admin/reports/board/test.html

使用shutil.copy

1
2
3
import shutil
shutil.copy('/local/mnt/workspace/user/Automation/swbuild/board/test_new.html',
            '/local/mnt/workspace/user/Automation/sw_admin/reports/board/test.html')