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'

相关文章

利用numpy和pandas处理csv文件中的时间方法

利用numpy和pandas处理csv文件中的时间方法

环境:numpy,pandas,python3 在机器学习和深度学习的过程中,对于处理预测,回归问题,有时候变量是时间,需要进行合适的转换处理后才能进行学习分析,关于时间的变量如下所示,...

python中dict使用方法详解

dict的特性 dict是python中的一个可变的数据类型,用{}表示,dict的key必须是不可变的数据类型,而value的数据类型可以任意。 格式:{key:value,key...

Python中turtle作图示例

Python中turtle作图示例

在Python里,海龟不仅可以画简单的黑线,还可以用它画更复杂的几何图形,用不同的颜色,甚至还可以给形状填色。 一、从基本的正方形开始 引入turtle模块并创建Pen对象: >...

tensorflow识别自己手写数字

tensorflow识别自己手写数字

tensorflow作为google开源的项目,现在赶超了caffe,好像成为最受欢迎的深度学习框架。确实在编写的时候更能感受到代码的真实存在,这点和caffe不同,caffe通过编写配...

Python类方法__init__和__del__构造、析构过程分析

最近学习《Python参考手册》学到Class部分,遇到了类的构造析构部分的问题: 1、什么时候构造? 2、什么时候析构? 3、成员变量如何处理? 4、Python中的共享成员函数如何访...