最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

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

来源:动视网 责编:小采 时间:2020-11-27 14:30:06
文档

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

python使用7z解压软件备份文件脚本分享:要求安装: 1.Python2.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:c
推荐度:
导读python使用7z解压软件备份文件脚本分享:要求安装: 1.Python2.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:c


要求安装:

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

文档

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

python使用7z解压软件备份文件脚本分享:要求安装: 1.Python2.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:c
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top