• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

python 搞代码 4年前 (2022-01-07) 60次浏览 已收录 0个评论

这篇文章主要介绍了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:’):
 

来源gaodai.ma#com搞##代!^码网

       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解压软件备份文件脚本分享的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python使用7z解压软件备份文件脚本分享

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址