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获取局域网占带宽最大3个ip的方法

python获取局域网占带宽最大3个ip的方法

本文实例讲述了python获取局域网占带宽最大3个ip的方法。分享给大家供大家参考。具体实现方法如下: import re import urllib url = 'http://a...

python使用pygame模块实现坦克大战游戏

python使用pygame模块实现坦克大战游戏

本文实例为大家分享了pygame模块实现坦克大战游戏的具体代码,供大家参考,具体内容如下 首先,第一步,游戏简单素材的准备。 炮弹,炮弹,坦克移动。音乐-开火素材。 其次,思路整理。 我...

python批量修改ssh密码的实现

由于工作需要本文主结合了excel表格,对表格中的ssh密码进行批量修改 以下是详细代码(python3): ''' 遇到问题没人解答?小编创建了一个Python学习交流QQ群:...

python+os根据文件名自动生成文本

python+os根据文件名自动生成文本

有时我们有很多文件(如图片),我们需要对每一个文件进行操作。 我们还需要一份文件的名字来进行遍历,这时我们首先需要建立一份文件名单,有时还会对文件名做一定的筛选,如我们只选择jpg格...

使用python实现baidu hi自动登录的代码

复制代码 代码如下:# _*_ coding:utf-8 _*_# name login_baidu.pyimport urllib,urllib2,httplib,cookielibd...