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'

相关文章

pandas求两个表格不相交的集合方法

pandas求两个表格不相交的集合方法

Hi,好久不见,我还是那颗翻滚的老鼠屎。处理数据时想求两个表格求不相交的部分,或许是对知识的匮乏限制了我的想象力,并未找到直接求的方法,在这里介绍老鼠屎技己使用的方法,希望对读者会有帮助...

django基于restframework的CBV封装详解

一.models数据库映射 from django.db import models # Create your models here. class Book(models.Mo...

opencv调整图像亮度对比度的示例代码

opencv调整图像亮度对比度的示例代码

图像处理 图像变换就是找到一个函数,把原始图像矩阵经过函数处理后,转换为目标图像矩阵.   可以分为两种方式,即像素级别的变换和区域级别的变换 Point operators (p...

Python 面向对象 成员的访问约束

在Python中是通过一套命名体系来识别成约的访问范围的 class MyObjec(object): username = "developerworks" # public _ema...

python实现鸢尾花三种聚类算法(K-means,AGNES,DBScan)

python实现鸢尾花三种聚类算法(K-means,AGNES,DBScan)

一.分散性聚类(kmeans) 算法流程: 1.选择聚类的个数k. 2.任意产生k个聚类,然后确定聚类中心,或者直接生成k个中心。 3.对每个点确定其聚类中心点。 4.再计算其聚类新中心...