Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第10章-解决问题-版本一代码Windows系统下运行问题 #3

Closed
comeCU opened this issue Jul 29, 2018 · 0 comments
Closed

第10章-解决问题-版本一代码Windows系统下运行问题 #3

comeCU opened this issue Jul 29, 2018 · 0 comments

Comments

@comeCU
Copy link

comeCU commented Jul 29, 2018

Windows系统下,代码问题:
01

  1. 首先Linux压缩命令想要在Windows下运行需要安装gnuwin32 zip,尝试下载,但好像有墙!

下载zip-3.0-setup.exe:https://github.com/kkeybbs/gnuwin32/tree/master/gnuwin32

  1. Windows下代码修正
# 5.使用命令对其打包,拼接命令
zip_command = "zip -qr %s %s" %(target, ' '.join(source))   # 注意%s 不需要引号
  1. 附上完整代码,相应目录做修改即可
#!/usr/bin/env python
# filename: backup_ver1.py
# 备份文件并打包成zip格式

import os
import time

# 1.需要备份打包的文件列表
# 注意:windows下目录格式
source = [r'C:\Users\Administrator\Desktop\test_backup1', r'C:\Users\Administrator\Desktop\test_backup2']

# 2.保存目录
target_dir = r'C:\Users\Administrator\Desktop\backup/' #windows下目录写法

# 3.保存后生成文件目录,文件名为当前日期时间
# 4.生成的文件为zip格式
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'

# 5.使用命令对其打包,拼接命令
zip_command = "zip -qr %s %s" %(target, ' '.join(source))   # 注意%s 不需要引号

# 运行
if os.system(zip_command) == 0:
    print('Successful backup to', target)    
else:
    print('Backup failed!')

02

@comeCU comeCU closed this as completed Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant