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'

相关文章

SELENIUM自动化模拟键盘快捷键操作实现解析

SELENIUM自动化模拟键盘快捷键操作实现解析

这篇文章主要介绍了SELENIUM自动化模拟键盘快捷键操作实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 平常我们会用到很多快...

Random 在 Python 中的使用方法

Random 在 Python 中的使用方法

1.random.random(): 会随机生成0-1之间的小数 例如: 2.random.uniform(min,max): 会随机生成 min - max 之间的小数,其中min...

Python向Excel中插入图片的简单实现方法

Python向Excel中插入图片的简单实现方法

本文实例讲述了Python向Excel中插入图片的简单实现方法。分享给大家供大家参考,具体如下: 使用Python向Excel文件中插入图片,这个功能之前学习xlwt的时候通过xlwt模...

PyTorch的深度学习入门之PyTorch安装和配置

PyTorch的深度学习入门之PyTorch安装和配置

前言 深度神经网络是一种目前被广泛使用的工具,可以用于图像识别、分类,物体检测,机器翻译等等。深度学习(DeepLearning)是一种学习神经网络各种参数的方法。因此,我们将要介绍的深...

Python编程之列表操作实例详解【创建、使用、更新、删除】

Python编程之列表操作实例详解【创建、使用、更新、删除】

本文实例讲述了Python列表操作。分享给大家供大家参考,具体如下: #coding=utf8 ''''' 列表类型也是序列式的数据类型, 可以通过下标或者切片操作来访问某一个或者某...