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'

相关文章

pandas中Timestamp类用法详解

由于网上关于Timestamp类的资料比较少,而且官网上面介绍的很模糊,本文只是对如何创建Timestamp类对象进行简要介绍,详情请读者自行查阅文档。 以下有两种方式可以创建一个Tim...

Python实现的计算器功能示例

Python实现的计算器功能示例

本文实例讲述了Python实现的计算器功能。分享给大家供大家参考,具体如下: 源码: # -*- coding:utf-8 -*- #! python2 from tkinter i...

Python遍历numpy数组的实例

在用python进行图像处理时,有时需要遍历numpy数组,下面是遍历数组的方法: [rows, cols] = num.shape for i in range(rows - 1...

对Python Class之间函数的调用关系详解

假设有Class A 和 Class B两个类,Class A中定义了a(),Class B中定义了b(). 现在我想在Class B中调用 Class A中的函数a()。此处介绍三种调...

python将html转成PDF的实现代码(包含中文)

前提: 安装xhtml2pdf https://pypi.python.org/pypi/xhtml2pdf/下载字体:微软雅黑;给个地址:https://www.jb51.net/fo...