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'

相关文章

举例讲解Django中数据模型访问外键值的方法

先设置一个关于书本(book)的数据模型: from django.db import models class Publisher(models.Model): name...

matplotlib subplots 调整子图间矩的实例

在matplotlib中,用subplots画子图时,有时候需要调整子图间矩,包括子图与边框的间矩,子图间上下间矩,子图间左右间矩,可以使用fig.tight_layout()函数:...

python实现对输入的密文加密

python实现对输入的密文加密

本文实例为大家分享了python实现对输入的密文加密的具体代码,供大家参考,具体内容如下 遇到这样一道题目,是要求把输入的明文进行加密,加密的方法是按照一定的转换规则进行相应的替换得到最...

详解Python的Django框架中的templates设置

TEMPLATES Django 1.8的新特性 一个列表,包含所有在Django中使用的模板引擎的设置。列表中的每一项都是一个字典,包含某个引擎的选项。 以下是一个简单的设定,告诉Dj...

搭建Python的Django框架环境并建立和运行第一个App的教程

搭建Python的Django框架环境并建立和运行第一个App的教程

Django是python中目前风靡的Web Framework, 那么什么叫做Framework呢, 框架能够帮助你把程序的整体架构搭建好, 而我们所需要做的工作就是填写逻辑, 而框架...