标签:blog http os 使用 ar 文件 div 问题 sp
学习Python时遇到一个备份的问题, 下面记录下。
使用Python 在windows 下备份文件。
有几个需要注意的地方:
1. 需下载 7 zip 下载地址 : http://www.7-zip.org/download.html 根据自己的系统下载对应的版本
2. 7 zip 安装路径中的文件夹名不能出现空格, 以我的为例默认是安装在 C:\Program Files 下。
Program Files 文件夹中有空格会导致导入失败,安装的时候自己按需要替换下. (我的安装路径 :C:\7-Zip)
#!/usr/bin/python
# Filename: backup.py
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = [r‘C:\Python34\Doc‘]
# 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 = r‘D:\Myback\\‘ # 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 = r"C:\7-Zip\7z.exe a %s %s" % (target, ‘‘.join(source))
# Run the backup
print (‘zip_command :‘,zip_command)
if os.system(zip_command) == 0:
print (‘Successful backup to‘, target)
else:
print (‘Backup FAILED‘)
标签:blog http os 使用 ar 文件 div 问题 sp
原文地址:http://www.cnblogs.com/minco/p/3968853.html