In the case of completing the backup_ver1.py, there are several problems encountered.
1. The tutorial is compressed with zip, and the native is not installed Zip,dos cannot execute the zip command.
Solved: Replace the rar command execution, which will C:/Program Files/winrar under the Rar.exe copy to%systemroot%/system32, so you do not have to set the environment variable RAR, and can directly re-cmd Use the RAR command at the command prompt.
which rar compression command for RAR a filesname.rar filesname
Reference http://blog.csdn.net/jianzhiying/article/details/5407579
or http://www.cnblogs.com/monkeyfather/p/4160142.html
2. The folder path used as an example contains spaces, and DOS does not correctly identify the compression path.
Solved: In the form of a compression path, add the "" character before and after the path, and note the ' \ ' escape character.
#!/usr/bin/env python#-*-coding:utf-8-*-# Filename:backup_ver1.py__author__ = ' Jerryqiu ' import osimport timesource = [ ' E:\\my files\\baby ']target_dir = ' e:\\my files\\ ' target = ' \ ' + target_dir + time.strftime ('%y%m%d ') + '. rar ' + ' \ "' rar _command = "rar A%s%s"% (target, ". Join (source)) Print Rar_commandif os.system (rar_command) = = 0: print ' successful Backup to ', Targetelse: print ' Backup Failed '
Python writes some of the problems encountered by the DOS compression example