当前位置: 移动技术网 > IT编程>脚本编程>Python > windows系统中python使用rar命令压缩多个文件夹示例

windows系统中python使用rar命令压缩多个文件夹示例

2019年03月30日  | 移动技术网IT编程  | 我要评论

神纹布,270004,爱就爱 张靓颖

复制代码 代码如下:

#!/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'

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网