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中的matplotlib绘制方程图像代码

用python中的matplotlib绘制方程图像代码

import numpy as np import matplotlib.pyplot as plt def main(): # 设置x和y的坐标范围 x=np.aran...

python中单下划线(_)和双下划线(__)的特殊用法

函数使用单下划线_开头   使用单下划线(_)开头的函数_func不能被模块外部以: from module import *形式导入。   但可以用:from module imp...

python实现杨辉三角思路

程序输出需要实现如下效果: [1] [1,1] [1,2,1] [1,3,3,1] ...... 方法:迭代,生成器 def triangles() L = [1] while...

Python实现Kmeans聚类算法

本节内容:本节内容是根据上学期所上的模式识别课程的作业整理而来,第一道题目是Kmeans聚类算法,数据集是Iris(鸢尾花的数据集),分类数k是3,数据维数是4。 关于聚类  ...

在Docker上开始部署Python应用的教程

在Docker上开始部署Python应用的教程

几周前, Elastic Beanstalk声明在AWS云中配置和管理Docker容器。在本文中,我们通过一个简单的注册表单页面应用去理解Docker部署过程,该表单使用Elastic...