Speaking of the source of the program, is from the "Concise Python tutorial" above to see the program, after a try, home! Then No! Yes!!!
Google has long time, also read a lot of blog, also failed to solve.
In addition to some basic grammatical problems, string Squadron ' \ ' dealing with the problem, it is assumed that the program itself is not a problem, mainly zip_command this command appears. One of the most common problems is that zip is not the one with internal instructions, such as:
First of all, my solution is from the almighty to find the solution, words do not say, straight to the point.
Under a 7-zip software, install a bit, to remember your installation path!
Paste the code first, as shown below:
1 #-*-coding:utf-8-*-2 3 __author__='Leon'4 5 ImportOS6 Import Time7 8 #1 Save the folder that needs to be backed up into the list first9Source = [R'G:\test'R'G:\test2']Ten #2 Set Target save file directory OneTarget_dir ='d:\\' A #3 Save As ZIP format, canonical naming -target = Target_dir + time.strftime ('%y%m%d%h%m%s') +'. zip' - the PrintSource - PrintTarget - - #4 compressing files into a zip archive using the zip command command +Zip_command = R"D:\7-Zip\7z.exe a%s%s"% (target,' '. Join (source))#Note that there is a unit of whitespace between the ' - + #Run A ifOs.system (zip_command) = =0: at Print 'file has been successfully backed up to'+Target - Else: - Print 'Backup Failed ...'
The Zip_command location of the zip command orientation in the D:\7-zip\7z.exe is where the software is installed.
Here is the result of my output:
D:\Python27\python.exe e:/mydamnwork/backup_ver01/ver_01.py
[' G:\\test ', ' g:\\test2 ']
D:\20150906214804.zip
7-zip [9.20] Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Scanning
Creating Archive D:\20150906214804.zip
Compressing test2\b (1). docx
Compressing test2\b (1). pdf
Compressing test2\b (1). txt
Compressing test2\b (2). docx
Compressing test2\b (2). txt
Compressing test\a (1). jpg
Compressing test\a (2). jpg
Compressing test\a (3). jpg
Compressing test\a (4). jpg
Compressing test\a (5). jpg
Everything is Ok
File has been successfully backed up to D:\20150906214804.zip
Process finished with exit code 0
After opening the compressed file:
Original link: http://www.cnblogs.com/leonwen/p/4787492.html
Python backup script (win10+python2.7+pycharm)