1, Windows does not own the zip, need to install itself, http://gnuwin32.sourceforge.net/packages/zip.htm
2, after installation, to configure environment variables: PATH
3. backup_ver1.py Code in the Concise Python tutorial (A Byte of Python)
Import Osimport time#1, files and directories that need to be backed up will be specified in a list. #windows下source = [' "" C:\\My Documents "', ' C:\\code '] #这里要注意, we must enclose the string in double quotation marks, because there are spaces in the string. #2, the backup file must be stored in a primary backup directory under #windows target_dir = ' e:\\backup ' #3, the backup file will be packaged and compressed into a zip file. The name of the #4, Zip compressed file is comprised of the current date and time. target = Target_dir + os.sep + time.strftime ('%y%m%d%h%m%s ') + '. zip ' #如果目标目录还不存在, then create if not os.path.exists (target_ DIR): os.mkdir (Target_dir) #创建目录 # #, we are using the zip command to package the file in zip format Zip_command = ' zip-r {0} {1} '. Format (target, ". Join ( SOURCE)) #运行备份print (' Zip command is: ') print (zip_command) print (' Running: ') if Os.system (zip_command) = = 0: print (' Successful backup to ', Target ' else: print (' Backup FAILED ')
4, the first time the operation, the output of the Pycharm display Backup FAILED, and accompanied by garbled, as follows:
' Zip '???????????????????????? Keyboard????
?????????????
Backup FAILED
5, online check for a long time, some say do not use zip for WinRAR, 7-zip, some said Pycharm font display has the problem of de encoding set to GBK ... Wait, all have tried (this middle has not shut down pycharm restart), have no effect.
6, finally I bored, restart a pycharm, the result is good!
7, do not know what the reason, together pondering it! Ha ha...
8, there is a doubt: once I chose the way in the run "Run File in Console", the result has been shown, close the page, restart Pycharm no way to restore the original appearance, who knows how to do?
Python--pycharm backup_ver1.py Console has been backup FAILED