备份/复制分批或Python的整个文件夹树? [英] Backing up/copying an entire folder tree in batch or python?
问题描述
我想通过Python从一个地方的整个目录复制到另一个每隔7天基本上做一个备份...
I'm trying to copy an entire directory from one locations to another via python every 7 days to essentially make a backup...
备份文件夹/树文件夹可能会或可能不会存在,因此它需要创建的文件夹,如果它不存在,这就是为什么我认为的distutils
更适合在 shutil
The backup folder/tree folder may or may not exist so it needs to create the folder if it doesn't exist, that's why I assumed distutils
is better suited over shutil
注意它是我最好使用批处理或其他语言的说工作?
Note Is it better for me to use batch or some other language for the said job?
以下code:
import distutils
distutils.dir_util.copy_tree("C:\Users\A\Desktop\Test", "C:\Users\A\Desktop\test_new", preserve_mode=1, preserve_times=1, preserve_symlinks=0, update=1, verbose=0, dry_run=0)
返回:
Traceback (most recent call last):
File "C:\Users\A\Desktop\test.py", line 2, in <module>
distutils.dir_util.copy_tree("C:\Users\A\Desktop\test", "C:\Users\A\Desktop\test2", preserve_mode=1, preserve_times=1, preserve_symlinks=0, update=1, verbose=0, dry_run=0)
AttributeError: 'module' object has no attribute 'dir_util'
我在做什么错了?
What am I doing wrong?
在此先感谢
- HYFLEX
Thanks in advance - Hyflex
推荐答案
对于Unix / Linux上,我建议' rsync的。
对于Windows:<一href=\"https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true\"相对=nofollow> XCOPY
For Unix/Linux, I suggest 'rsync'. For windows: xcopy
这篇关于备份/复制分批或Python的整个文件夹树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!