压缩命令和目录 (Windows) 问题

发布于 2024-12-06 14:18:16 字数 1237 浏览 1 评论 0原文

问题是“我想要一个程序来创建我所有重要文件的备份”。

本课程位于: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶色山野 2024-12-13 14:18:16

您可以从 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's zipfile module.

Also, there's no standard backup file location. You'll just have to make one up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文