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调取任意数字资产钱包余额功能

当我们的资产放在交易所的时候,可以通过链接交易所的API使用Python来监控余额。 那资产放在钱包的时候,如何来监控余额呢? 任何数字资产都可以使用区块浏览器来查询余额,那我们只要从此...

python实现报表自动化详解

python实现报表自动化详解

本篇文章将介绍: xlwt 常用功能 xlrd 常用功能 xlutils 常用功能 xlwt写Excel时公式的应用 xlwt写入特定目录(路径设置) xlwt Python语言中,写...

Python编程求解二叉树中和为某一值的路径代码示例

题目描述 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。 思路:首先要理解题意,是从根节点往...

python获取android设备的GPS信息脚本分享

在android上,我们可以使用QPython来编写、执行Python脚本。它对很多android 系统函数进行了方便的封装,使用QPython编写功能简单的小程序异常方便。 这个示例是...

PyCharm安装Markdown插件的两种方法

PyCharm安装Markdown插件的两种方法

Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式。 从github下载的代码一般都会带有README.md文件,该文件是...