国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用7z解壓軟件備份文件腳本分享

2020-02-23 05:10:22
字體:
供稿:網(wǎng)友

要求安裝:

1.Python
2.7z解壓軟件

backup_2.py

代碼如下:
# 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')

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳原县| 华蓥市| 府谷县| 清苑县| 青河县| 中卫市| 嘉鱼县| 特克斯县| 辽源市| 右玉县| 宜黄县| 江北区| 六枝特区| 民县| 武川县| 保亭| 宜宾县| 沙坪坝区| 宜州市| 玉山县| 邵东县| 南木林县| 大名县| 缙云县| 乌兰县| 连城县| 白山市| 泸溪县| 杭州市| 政和县| 康定县| 泰和县| 庆云县| 开原市| 阿克| 湛江市| 通辽市| 伊金霍洛旗| 长岭县| 易门县| 建昌县|