Python 压缩命令和目录(Windows)问题
问题是“我想要一个能备份我所有重要文件的程序” 本课程位于: 我正在使用Windows。 对于#2,这在哪里?它是否适用于Windows? 对于#5,我找不到为默认windows压缩程序压缩文件的命令Python 压缩命令和目录(Windows)问题,python,zip,ziparchive,Python,Zip,Ziparchive,问题是“我想要一个能备份我所有重要文件的程序” 本课程位于: 我正在使用Windows。 对于#2,这在哪里?它是否适用于Windows? 对于#5,我找不到为默认windows压缩程序压缩文件的命令 如果本课程解释了如何在Windows和压缩命令中使用此功能,那么这将很容易。感谢您的帮助。这是家庭作业阅读,但如果没有定义所有适用的工具,则没有帮助。您可以从中获得zip程序,但我建议只使用Python模块 此外,没有标准的备份文件位置。你只需要补一个就行了。太好了。该程序的d/l镜像已冻结:(我
如果本课程解释了如何在Windows和压缩命令中使用此功能,那么这将很容易。感谢您的帮助。这是家庭作业阅读,但如果没有定义所有适用的工具,则没有帮助。您可以从中获得
zip
程序,但我建议只使用Python模块
此外,没有标准的备份文件位置。你只需要补一个就行了。太好了。该程序的d/l镜像已冻结:(我需要阅读有关该模块的信息。当我创建备份文件位置时,我可以在桌面上创建一个新文件夹并使用它,对吗?谢谢!您可以在获得较旧(但仍然有用)版本的
zip
at。并且您可以使用桌面上的文件夹进行备份。
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'