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中open函数的使用

探究python中open函数的使用

最近,开始学习python的开发,遇到了一点文件操作的问题,探究一下open函数的使用。 一、open()的函数原型 open(file, mode=‘r', buffering=-1,...

Python弹出输入框并获取输入值的实例

使用自带的Tkinter模块,简单的弹输入框示例,返回输入值 from Tkinter import * import tkMessageBox def getInput(t...

Python批处理更改文件名os.rename的方法

在工作中,我们经常会遇到需要对大批量文件进行重命名的操作,而python提供了很简单的方法: import os #top是目标文件夹(绝对路径),os.walk会读取其内的文件及...

跟老齐学Python之集成开发环境(IDE)

跟老齐学Python之集成开发环境(IDE)

当安装好python之后,其实就已经可以进行开发了。下面我们开始写第一行python代码。 值得纪念的时刻:Hello world 如果是用windows,请打开CMD,并执行pytho...

pandas中DataFrame修改index、columns名的方法示例

一般常用的有两个方法: 1、使用DataFrame.index = [newName],DataFrame.columns = [newName],这两种方法可以轻松实现。 2、使用...