压缩命令和目录 (Windows) 问题
问题是“我想要一个程序来创建我所有重要文件的备份”。
本课程位于:http://www.ibiblio.org/g2swap /byteofpython/read/problem-solving.html
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
我使用的是 Windows。 对于#2,它在哪里?它是否适用于 Windows? 对于 # 5,我找不到用于默认 Windows 压缩程序压缩文件的命令。
如果课程解释了如何在 Windows 和压缩命令中使用它,那么这将很容易。如有任何帮助,我们将不胜感激。这是家庭作业阅读,但当所有适用的工具都没有定义时,它没有帮助。
The problem is 'I want a program which creates a backup of all my important files'.
This lesson is located at: http://www.ibiblio.org/g2swap/byteofpython/read/problem-solving.html
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
I'm using Windows.
For # 2, where is this and does it apply to Windows?
For # 5, I can't find the commands to zip a file for the default windows zipping program.
This would be easy if the lesson explained how to use this with Windows and the zipping commands. Any assistance is appreciated. This is homework reading but It's not helpful when all the applicable tools are not defined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从 http://info-zip.org/Zip 获取
zip
程序.html 但我建议只使用 Python 的zipfile
模块。此外,没有标准的备份文件位置。你只需要补一张。
You can get a
zip
program from http://info-zip.org/Zip.html but I would recommend just using Python'szipfile
module.Also, there's no standard backup file location. You'll just have to make one up.