小白学python

来源:互联网 发布:影视vip软件下载 编辑:程序博客网 时间:2024/06/05 15:15

简明python教程中:我想要一个可以为我的所有重要文件创建备份的程序。这个由于原作者是使用linux写的,所以zip—command在Windows系统下面会报错。在用info-zip和7zip无果的情况下,试了一下winrar命令,最后居然成功了。程序如下:

#!/usr/bin/python
#Filename:backup_verl.py


import os
import time


#The files and directories to be backed up are specified in a list
source=[r'E:\ds',r'F:\py123']


#The back up must be stored in a main backup directory
target_dir='/m n t/e/backup/' #Remember to change this to what you will be using




#The files are backed up into a zip file
#The name of the zip archive is the current date and time
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'


#sue the winrar command to put the files in a zip archive
WinRaR_command="WinRaR a {0} {1}".format(target,source)


#Run the backup
if os.system (WinRaR_command)==0:
    print'Sucessful back up to',target
else:
    print'Bcakup FAILED'


程序具体情况明天分析,朋友叫我跑步啦。遇到问题不要放弃,问题是用来解决而不是遗忘的。

0 0