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脚本实现虾米网签到功能

本文实例讲述了Python脚本实现虾米网签到功能的方法。分享给大家供大家参考,具体如下: 概述 这个脚本完成了自动登录虾米网、签到的功能。 大致要用到urllib、urllib2、coo...

python求质数的3种方法

本文为大家分享了多种方法求质数python实现代码,供大家参考,具体内容如下 题目要求是求所有小于n的质数的个数。 求质数方法1: 穷举法: 根据定义循环判断该数除以比他小的...

python实现随机梯度下降法

python实现随机梯度下降法

看这篇文章前强烈建议你看看上一篇python实现梯度下降法: 一、为什么要提出随机梯度下降算法 注意看梯度下降法权值的更新方式(推导过程在上一篇文章中有)  也就是说每次更新...

解决Python命令行下退格,删除,方向键乱码(亲测有效)

一、出现原因:readline模块没有安装 二、解决方式: # 安装readline模块 yum -y install readline-devel # 进入Python安装目录 c...

Python 打印中文字符的三种方法

方法一: 现在用 notepad++,在 UTF-8 格式下编写以下语句: #coding=utf-8 print"打印中文字符" 方法二: 用encode和decode 如:...