最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2014年02月21日 15:43:30   作者:  
這篇文章主要介紹了python使用7z解壓軟件備份文件腳本,需要的朋友可以參考下

要求安裝:

1.Python
2.7z解壓軟件

backup_2.py

復(fù)制代碼 代碼如下:

# 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')

相關(guān)文章

最新評(píng)論

图木舒克市| 庆阳市| 乐都县| 宿州市| 偃师市| 宁海县| 湖北省| 三明市| 赞皇县| 丰都县| 玛曲县| 项城市| 鹤庆县| 高淳县| 上林县| 民丰县| 开平市| 常宁市| 鲜城| 珲春市| 屯昌县| 长岭县| 泰兴市| 扶风县| 马关县| 尼木县| 四川省| 玉山县| 长乐市| 巴中市| 阳西县| 东丰县| 靖宇县| 揭东县| 石狮市| 吉林省| 屏东市| 五莲县| 五峰| 博爱县| 麻阳|