windows系统中python使用rar命令压缩多个文件夹示例
#!/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']
source=['d:\\filecopier\\*.*','d:\\jeecms_doc\\*.*']
# 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
target_dir='e:\\temp\\' #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))
zip_command="rar a " + target + ' '.join(source)
# run the backup
if os.system(zip_command)==0:
print 'successful backup to',target
else:
print 'backup failed'
上一篇: 如何代理刚上市的新产品?新产品怎么做推广