python解压7z文件_python使用7z解压软件备份文件脚本分享

# Filename: backup_2.py

'''Backup files.

Version: V2, based on Python 3.3

Usage: backup.py -s:"dir1|dir2|..." -t:"target_dir" [-c:"comment"]

-s: The source directories.

-t: The target directory.

-c: Optional, any comment.

Examples:

backup.py -s:"c:\\src\\F1|c:\\src\\F2|c:\\src\\F 3" -t:"c:\\backup"

backup.py -s:"c:\\src\\F 3" -t:"c:\\backup" -c:"For sample"'''

import os

import sys

import time

# Read sys.argv

print(sys.argv)

if len(sys.argv) < 2:

print(__doc__)

sys.exit()

source=[]

target_dir=''

comment=''

for arg in sys.argv:

if arg.startswith('-s:'):

source=arg[3:].split('|')

print(source)

elif arg.startswith('-t:'):

target_dir=arg[3:]+os.sep

print(target_dir)

elif arg.startswith('-c:'):

comment=arg[3:]

print(comment)

for i in range(0, len(source)):

source[i] = "\"" + source[i] + "\""

print(source[i])

# Make the file name with the time and comment

today=target_dir+time.strftime('%Y%m%d')

now=time.strftime('%H%M%S')

if len(comment)==0: # check if a comment was entered

target=today+os.sep+now+'.7z'

else:

target=today+os.sep+now+'_'+\

comment.replace(' ','_')+'.7z'

# Create the subdirectory by day

if not os.path.exists(today):

os.mkdir(today) # make directory

print('Successfully created directory',today)

# zip command

zip_command="7z a %s %s" %(target,' '.join(source))

print(zip_command)

# Run the backup

if os.system(zip_command)==0:

print('Successful backup to',target)

else:

print('Backup FAILED')

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值