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写xml文件的操作实例

本文实例讲述了python写xml文件的操作的方法,分享给大家供大家参考。具体方法如下: 要生成的xml文件格式如下: <?xml version="1.0" ?...

解决pycharm 安装numpy失败的问题

解决pycharm 安装numpy失败的问题

pycharm安装numpy失败,问题是 解决办法: 配置系统变量 path 新加 然后在cmd 命令行里添加 之后pycharm里面就有了 numpy 以上这篇解决pychar...

Flask框架URL管理操作示例【基于@app.route】

本文实例讲述了Flask框架URL管理操作。分享给大家供大家参考,具体如下: 动态URL规则 URL规则可以添加变量部分,也就是将符合同种规则的URL抽象成一个URL模式,如“/item...

Python3多线程版TCP端口扫描器

本文实例为大家分享了Python3多线程版TCP端口扫描器的具体代码,供大家参考,具体内容如下 使用命令 python BannerDemo.py -H 192.168.200.10...

Selenium chrome配置代理Python版的方法

环境: windows 7 + Python 3.5.2 + Selenium 3.4.2 + Chrome Driver 2.29 + Chrome 58.0.3029.110 (64...