免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3296 | 回复: 2
打印 上一主题 下一主题

这段代码 怎样改才能在windows 下进行备份文件呢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-04 12:07 |只看该作者 |倒序浏览
#!/usr/bin/env python
# Filename: backup_ver1.py

import os
import time

# 1. The files and directories to be backed up are specified in a list.
source=['/home/swaroop/byte','/home/swaroop/bin']
# If you are using Windows, use source=[r'C:\Documents',r'D:\Work'] or something like that

# 2. The backup must be stored in a main backup directory
target_dir='/mnt/e/backup/' #Remember to change this to what you will be using

# 3. The files are backed up into a zip file
# 4. The name of the zip archive is the current date and time
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'

# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command="zip -qr '%s' %s" %(target,' '.join(source))

# Run the backup
if os.system(zip_command)==0:
        print 'Successful backup to',target
else:
        print 'Backup FAILED'

论坛徽章:
0
2 [报告]
发表于 2005-09-04 14:29 |只看该作者

这段代码 怎样改才能在windows 下进行备份文件呢

在windows上用,目录的写法要给,代码的注释已经说明了,还有zip_command要改一下,你用7-zip

论坛徽章:
0
3 [报告]
发表于 2005-09-05 09:29 |只看该作者

这段代码 怎样改才能在windows 下进行备份文件呢

os.sep是代表目录分割符,根据操作系统不同而不同,可以用它来替代实现兼容.

python 自身有zip模块的.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP