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'

相关文章

在NumPy中创建空数组/矩阵的方法

如何在NumPy中创建空数组/矩阵? 在添加行的情况下,你最好的选择是创建一个与数据集最终一样大的数组,然后向它添加数据 row-by-row: >>> impo...

python模块之sys模块和序列化模块(实例讲解)

python模块之sys模块和序列化模块(实例讲解)

sys模块 sys模块是与python解释器交互的一个接口 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit...

Python 将json序列化后的字符串转换成字典(推荐)

一般而言下面的就可以完成需求了。 def convertToDic(data): jsonDic=json.loads(data) return dict(jsonDic) 但...

Python使用MYSQLDB实现从数据库中导出XML文件的方法

本文实例讲述了Python使用MYSQLDB实现从数据库中导出XML文件的方法。分享给大家供大家参考。具体分析如下: 这里需要给前端以xml格式提供一些数据,这些数据在目前的数据库中已经...

Django基础知识与基本应用入门教程

Django基础知识与基本应用入门教程

本文实例讲述了Django基础知识与基本应用。分享给大家供大家参考,具体如下: MVC模式和MTV模式 MVC model view controller MTV model templ...