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 不同级目录之间模块的调用方法

Python的模块有自带的也有第三方,还可以自定义然后引用 1、调用自带的模块,例如,sys 调用自带的模块只需要import sys 引入既可以使用 2、第三方的需要先安装模块然后再i...

python绘图方法实例入门

本文实例讲述了python绘图方法。分享给大家供大家参考。具体如下: # -*- coding:utf-8 -*- import matplotlib.pyplot as plt d...

pip命令无法使用的解决方法

今天在学习Python时需要安装Requests    使用命令:pip install requests    &...

Python三级目录展示的实现方法

Python三级目录展示的实现方法

要求: 1、三级菜单 2、可依次选择进入各子菜单,选择序号进入目录 3、输入b返回上级目录,q退出更改目录 代码实现: #!/bin/env python #!--*--co...

Python Socket实现简单TCP Server/client功能示例

本文实例讲述了Python Socket实现简单TCP Server/client功能。分享给大家供大家参考,具体如下: 网络上关于socket的介绍文章数不胜数。自己记录下学习的点点滴...