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操作列表之List.insert()方法的使用

 insert()方法插入对象obj到列表的偏移量索引。 语法 以下是insert()方法的语法: list.insert(index, obj) 参数 &nb...

树莓派采用socket方式文件传输(python)

树莓派采用socket方式文件传输(python)

两个树莓派,在同一个局域网内,传输文件,采用socket方式。 client端代码: import socket import os import hashlib client =...

python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

将时间信息“2018-02-04  18:23:35“ 解析成字典形式的结果 如:{‘year':2018,‘month':2,‘day':4,‘hour':18:‘minut...

Python排序搜索基本算法之希尔排序实例分析

Python排序搜索基本算法之希尔排序实例分析

本文实例讲述了Python排序搜索基本算法之希尔排序。分享给大家供大家参考,具体如下: 希尔排序是插入排序的扩展,通过允许非相邻的元素进行交换来提高执行效率。希尔排序最关键的是选择步长,...

Python pymongo模块常用操作分析

Python pymongo模块常用操作分析

本文实例讲述了Python pymongo模块常用操作。分享给大家供大家参考,具体如下: 环境:pymongo3.0.3,python3 以下是我整理的一些关于pymongo的操作,网上...