python备份文件
来源:互联网 发布:淘宝首页广告位价格 编辑:程序博客网 时间:2024/06/10 02:22
转载:http://zhouyangchenrui.iteye.com/blog/682143
python备份文件的例子在windows下采用winrar的rar命令运行可以成功,只是要有winrar软件和设置其环境变量。
- # Filename: backup_ver4.py
- import os
- import time
- # 1.需要备份的文件目录
- source = ['F:\\python\\code']
- # 2. 备份文件到目标路径
- target_dir = 'F:\\python\\backup\\'
- # 3. The files are backed up into a zip file.
- # 4. The current day is the name of the subdirectory in the main directory
- today = target_dir + time.strftime('%Y%m%d')
- # The current time is the name of the zip archive
- now = time.strftime('%H%M%S')
- # Take a comment from the user to create the name of the zip file
- comment = raw_input('Enter a comment -->')
- if len(comment)==0:
- target = today+os.sep+now+'.zip'
- else:
- target = today+os.sep+now+'_'+\
- comment.replace(' ','_')+'.zip'
- # Notice the backslash!
- # Create the subdirectory if it isn't already there
- if not os.path.exists(today):
- os.mkdir(today) # make directory
- print('Successfully created directory', today)
- # 5. 用winrar的rar命令压缩文件,但首先要安装有winrar且设置winrar到环境变量的路径path中
- zip_command = "rar a %s %s" %(target,''.join(source))
- # Run the backup
- #设置winrar到path环境中,这里已经手动添加,如图
- #os.system('set Path=%Path%;C:\Program Files\WinRAR')
- if os.system(zip_command)==0:
- print('Successful backup to', target)
- else:
- print('Backup FAILED')
设置winrar环境变量如下图:
- python 备份文件
- python备份文件
- python备份文件
- Python备份文件
- Python 备份文件
- Python 实例: 备份文件
- python备份文件2
- python 备份文件脚本
- Python备份文件脚本
- 备份文件的python脚本
- python <2> 压缩备份文件
- 用python脚本定期备份文件
- 第一个python程序:备份文件
- 编写Python脚本来备份文件
- Python小脚本 001 备份文件
- python 备份文件的小脚本
- 备份文件
- 使用python解析火狐的书签备份文件
- 关注程序员健康之——用脑过度多吃松子 ++——白天打个盹提高记忆力
- 439 - Knight Moves
- POJ 2635 The Embarrassed Cryptographer
- POJ 1942 Paths on a Grid
- Git详解之二 Git基础
- python备份文件
- oracle如何查询和停止正在运行的job
- 第一次用JQUERY做导航栏目
- POJ 3252 Round Number
- 你知道吗?红酒可以美容养颜的!
- Android牟利之道(五)--界面嵌入多盟广告
- VMWARE 网络桥接方式下,指定网络连接
- oracle net manager
- ssd 损耗平衡算法