python使用7z解壓軟件備份文件腳本分享
要求安裝:
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')
相關(guān)文章
python中round函數(shù)保留兩位小數(shù)的方法
在本篇內(nèi)容里小編給各位分享的是一篇關(guān)于python中round函數(shù)保留兩位小數(shù)的方法及相關(guān)知識點,有興趣的朋友們可以學(xué)習(xí)下。2020-12-12
PyTorch學(xué)習(xí)筆記之回歸實戰(zhàn)
這篇文章主要介紹了PyTorch學(xué)習(xí)筆記之回歸實戰(zhàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05
Postman安裝與使用詳細教程 附postman離線安裝包
這篇文章主要介紹了Postman安裝與使用詳細教程 附postman離線安裝包,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
Python3.9.0 a1安裝pygame出錯解決全過程(小結(jié))
這篇文章主要介紹了Python3.9.0 a1安裝pygame出錯解決全過程(小結(jié)),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
Python?NumPy教程之數(shù)組的創(chuàng)建詳解
這篇文章主要為大家詳細介紹了Python?NumPy中數(shù)組的創(chuàng)建方式,文中的示例代碼講解詳細,對我們學(xué)習(xí)Python有一定幫助,需要的可以參考一下2022-08-08
pycharm 關(guān)閉search everywhere的解決操作
這篇文章主要介紹了pycharm 關(guān)閉search everywhere的解決操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01
徹底吃透理解Python基礎(chǔ)33個關(guān)鍵字詳細教程
這篇文章主要為大家介紹了徹底吃透理解Python中33個關(guān)鍵字的詳細教程,有需要打好Python基礎(chǔ)的同學(xué)可以借鑒參考下,希望能成為您成功路上的一塊墊腳石2021-10-10
python3使用urllib示例取googletranslate(谷歌翻譯)
這篇文章主要介紹了使用urllib取googletranslate(谷歌翻譯)的示例,通過這個谷歌翻譯示例學(xué)習(xí)python3中urllib的使用方法,2014-01-01

