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 中的lambda函数介绍

Lambda函数,即Lambda 表达式(lambda expression),是一个匿名函数(不存在函数名的函数),Lambda表达式基于数学中的λ演算得名,直接对应于其中的lambd...

Python数据可视化:顶级绘图库plotly详解

Python数据可视化:顶级绘图库plotly详解

有史以来最牛逼的绘图工具,没有之一 plotly是现代平台的敏捷商业智能和数据科学库,它作为一款开源的绘图库,可以应用于Python、R、MATLAB、Excel、JavaScript...

python用户管理系统

本文实例为大家分享了Python用户管理系统的具体代码,供大家参考,具体内容如下 用户管理系统 1.注册新用户 如果注册用户已经存在,则报错 需要填写信息: name, passw...

Python返回真假值(True or False)小技巧

Python返回真假值(True or False)小技巧

在昨天关于substring的blog中有如下一段代码: 也许你已经发现,在Python 3中其实有办法只用一行完成函数: 复制代码 代码如下: >>> def is...

将图片文件嵌入到wxpython代码中的实现方法

将图片文件嵌入到wxpython代码中的实现方法

下面直接上代码留存,方便以后查阅复用。 # -*- coding: utf-8 -*- #作者:LeniyTsan #时间:2014-07-17 import wx from...