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

yipeiwu_com6年前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多继承(钻石继承)问题和解决方法。分享给大家供大家参考,具体如下: 在菱形多继承中,如果用父类.__init__()来调用父类的初始化方法,最上层会执行两次,所...

python多线程编程中的join函数使用心得

python多线程编程中的join函数使用心得

今天去辛集买箱包,下午挺晚才回来,又是恶心又是头痛。恶心是因为早上吃坏东西+晕车+回来时看到车祸现场,头痛大概是烈日和空调混合刺激而成。没有时间没有精神没有力气学习了,这篇博客就说说py...

浅谈Python对内存的使用(深浅拷贝)

本文主要研究的是Python对内存的使用(深浅拷贝)的相关问题,具体介绍如下。 浅拷贝就是对引用的拷贝(只拷贝父对象) 深拷贝就是对对象的资源的拷贝 >>> a...

Python+微信接口实现运维报警

说到运维报警,我觉得都可以写个长篇历史来详细解释了报警的前世来生,比如最早报警都是用邮件,但邮件实时性不高,比如下班回家总不能人一直盯着邮箱吧,所以邮件这种报警方式不适合用来报紧急的故障...

Python 元类使用说明

我要一大群的类都具有一中特点,我怎么给他们加上呢?模板模板吗,我从这个模板创建一群类不就OK了?那就需要元类了。霍霍》 定义一个元类(就所一个类的模板!莫多想,还要记住这是类级别的,不是...