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实现文本文件合并

python合并文本文件示例代码。 python实现两个文本合并 employee文件中记录了工号和姓名 cat employee.txt: 100 Jason Smith 20...

详解python深浅拷贝区别

详解python深浅拷贝区别

在Python中对象的赋值其实就是对象的引用。当创建一个对象,把它赋值给另一个变量的时候,python并没有拷贝这个对象,只是拷贝了这个对象的引用而已。 浅拷贝:拷贝了最外围的对象本身,...

python网络编程之多线程同时接受和发送

本文实例为大家分享了python多线程同时接受和发的具体代码,供大家参考,具体内容如下 ''' 模仿qq 同时可以发送信息和接受信息多线程 ''' from socket imp...

解决Scrapy安装错误:Microsoft Visual C++ 14.0 is required...

问题描述 当前环境win10,python_3.6.1,64位。 在windows下,在dos中运行pip install Scrapy报错: building 'twisted.t...

Python os.access()用法实例

概述 os.access() 方法使用当前的uid/gid尝试访问路径。大部分操作使用有效的 uid/gid, 因此运行环境可以在 suid/sgid 环境尝试。 语法 acces...