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 等分切分数据及规则命名的实例代码

 将一份一亿多条数据的csv文件等分为10份,代码如下所示: import pandas as pd data = pd.read_csv('C:\\Users\\Pych...

Python实现的概率分布运算操作示例

本文实例讲述了Python实现的概率分布运算操作。分享给大家供大家参考,具体如下: 1. 二项分布(离散) import numpy as np from scipy import...

Python Xml文件添加字节属性的方法

实例如下所示: from xml.etree.cElementTree import ElementTree,Element import xlrd import re def re...

Python查找数组中数值和下标相等的元素示例【二分查找】

本文实例讲述了Python查找数组中数值和下标相等的元素。分享给大家供大家参考,具体如下: 题目描述: 假设一个单调递增的数组中的每个元素都是整数并且是唯一的。请编程实现一个函数,找出数...

Python两个内置函数 locals 和globals(学习笔记)

Python两个内置函数——locals 和globals 这两个函数主要提供,基于字典的访问局部和全局变量的方式。 在理解这两个函数时,首先来理解一下python中的名字空间概念。Py...