windows系统中python使用rar命令压缩多个文件夹示例

yipeiwu_com6年前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实现抖音点赞功能

本文实例为大家分享了python实现抖音点赞功能的具体代码,供大家参考,具体内容如下 #coding=utf-8 from time import sleep, ctime imp...

python中for语句简单遍历数据的方法

本文实例讲述了python中for语句简单遍历数据的方法。分享给大家供大家参考。具体如下: 复制代码 代码如下:for name in ["kak", "John", "Mani", "...

一篇文章读懂Python赋值与拷贝

一篇文章读懂Python赋值与拷贝

变量与赋值 在 Python 中,一切皆为对象,对象通过「变量名」引用,「变量名」更确切的叫法是「名字」,好比我们每个人都有自己的名字一样,咱们通过名字来代指某个人,代码里面通过名字来指...

Python中对列表排序实例

很多时候,我们需要对List进行排序,Python提供了两个方法,对给定的List L进行排序: 方法1.用List的成员函数sort进行排序 方法2.用built-in函数sorted...

Ubuntu下Python2与Python3的共存问题

Linux系统一般自带Python,有时候又自己下载了Python,因此有可能Python2和Python3同时存在。那么当我们在Terminal键入python的时候,会调出哪个Pyt...