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在命令行下使用google翻译(带语音)

说明1. 使用google翻译服务获得翻译和语音;2. 使用mplayer播放获得的声音文件,因此,如果要播放语音,请确保PATH中能够找到mplayer程序,如果没有mplayer,请...

神经网络python源码分享

神经网络python源码分享

神经网络的逻辑应该都是熟知的了,在这里想说明一下交叉验证 交叉验证方法: 看图大概就能理解了,大致就是先将数据集分成K份,对这K份中每一份都取不一样的比例数据进行训练和测试。得出K个误...

安装Python的教程-Windows

安装Python的教程-Windows

在开始Python编程前,需要先安装Python环境。Python安装包可以到Python的官网下载,官网地址是https://www.python.org/,如果想直接跳过关于Pyth...

pandas DataFrame的修改方法(值、列、索引)

对于DataFrame的修改操作其实有很多,不单单是某个部分的值的修改,还有一些索引的修改、列名的修改,类型修改等等。我们仅选取部分进行介绍。 一、值的修改 DataFrame的修改方法...

django 框架实现的用户注册、登录、退出功能示例

本文实例讲述了django 框架实现的用户注册、登录、退出功能。分享给大家供大家参考,具体如下: 1 用户注册: from django.contrib import auth fr...