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

yipeiwu_com5年前Python基础

复制代码 代码如下:

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

相关文章

Python多线程及其基本使用方法实例分析

本文实例讲述了Python多线程及其基本使用方法。分享给大家供大家参考,具体如下: 学习Python的多线程(Multi-threading),至少应该要有进程与线程的基本概念,可以参考...

Ubuntu下安装PyV8

这几天需要在使用PyV8来进行python与javascript的交互。之前在window下安装过,直接使用的exe安装的,也没有遇到什么问题。 结果这次在Ubuntu安装遇到了不少坑-...

python开发之str.format()用法实例分析

本文实例分析了python开发之str.format()用法。分享给大家供大家参考,具体如下: 格式化一个字符串的输出结果,我们在很多地方都可以看到,如:c/c++中都有见过 下面看看p...

简介Python的collections模块中defaultdict类型的用法

defaultdict 主要用来需要对 value 做初始化的情形。对于字典来说,key 必须是 hashable,immutable,unique 的数据,而 value 可以是任意的...

django2.2安装错误最全的解决方案(小结)

安装报错类型,解决方案; 1. 数据库连接报错 mysqldb只支持python2,pymysql支持3,都是使用c写的驱动,性能更好 # django中修改配置文件setting...