您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

python在windows下实现备份程序实例

2024/4/8 0:36:52发布6次查看
很多书籍里面讲的python备份都是在linux下的,而在xp上测试一下也可以执行备份功能,代码都差不多相同,就是到执行打包的时候是不一样的。而且要用到winrar,其他的压缩文件也是一样的。
首先我们要把winrar的路径添加到path里面,这里添加完了要重启机子才有效。
这里要注意:把winrar的路径添加到path里面之后一定要重启,否则path的设定不会起作用,打包就会失败!
这里用到得命令是:winrar a xxx.zip xxxx
xxx为任意字符
实例代码如下:
#备份脚本,用来备份的 #filename:backup_ver1.py import os import time import sys #备份的源文件路径 sourc = ['g://test//test.txt'] #备份的文件所放的地方 target_dir = 'g://' #备份文件的名字 target = target_dir + time.strftime('%y%m%d%h%m%s')+'.rar' #zip_command = zip -qr '%s' %s % (target,''.join(sourc)) #zip_command = winrar a /%s/ %s % (target,' '.join(sourc)) zip_command=winrar a %s %s %(target,' '.join(sourc)) print zip_command if os.system(zip_command) == 0: print '打包成功!'+target else: print '打包失败!
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product