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'

相关文章

如何在VSCode上轻松舒适的配置Python的方法步骤

如何在VSCode上轻松舒适的配置Python的方法步骤

前言 之前被学长推荐使用了VSCode,后惊叹了VSCode的强大,尤其是他的配置,比之前使用sublime方便多了,刚好实验室也来了一批新的学弟学妹,来仔细的逐步的讲解一些,在自己的电...

Python中的函数式编程:不可变的数据结构

让我们首先考虑正方形和长方形。如果我们认为在接口方面,忽略了实现细节,方块是否是矩形的子类型? 子类型的定义取决于Liskov代换原理。为了成为一个子类型,它必须能够完成超级类型所做的一...

python快速排序代码实例

一、 算法描述: 1.先从数列中取出一个数作为基准数。2.分区过程,将比这个数大的数全放到它的右边,小于或等于它的数全放到它的左边。3.再对左右区间重复第二步,直到各区间只有一个数。 &...

Python运维之获取系统CPU信息的实现方法

使用Python进行运维工作的时候有时候需要获取CPU的信息,这在psutil模块库的帮助下非常容易实现。 常见的CPU信息有以下几种: 1,用户时间以及百分比; 2,系统时间以及百分比...

Python中的异常处理简明介绍

python异常处理机制和java类似,采用try-except-finally的结构. try-except检测异常 格式 复制代码 代码如下: try:   &n...