The first time to learn python written script 650) this.width=650; "src=" Http://img.baidu.com/hi/tsj/t_0015.gif "alt=" T_0015.gif "/>
The original script of the first script in the concise Python tutorial is as follows
#!/usr/bin/python# filename: backup_ver1.pyimport osimport time# 1. the Files and directories to be backed up are specified in a list.source = ['/home/swaroop/byte ', '/home/swaroop/bin ']# 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 directorytarget_dir = '/mnt/e/backup/' # 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 timetarget = 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 archivezip_command = "zip - qr '%s ' %s ' % (target, ' '. Join (source)) # run the backupif Os.system (Zip_command) == 0: print ' Successful backup to ', targetelse: print ' backup failed '
Because the original script is under Linux, the individual modifies the script under Windows
#coding =utf-8import osimport timeimport sysreload (SYS) sys.setdefaultencoding (' GBK ') Source = ' f:\\movie\\ text effect \ \ ' Target_dir = ' f:\\backup\\ ' target = target_dir + time.strftime ('%y%m%d%h%m%s ') + '. zip ' Un_source = Unicode (source, ' UTF8 ') ) Zip_command = "7z a-tzip%s%s-r"% (target,un_source) print zip_commandif os.system (zip_command) = = 0:print ' Succes Sful backup to ', Targetelse:print ' backup FAILED '
The following code is available because the folder path to be backed up exists in Chinese
Import sysreload (SYS) sys.setdefaultencoding (' GBK ')---------------------------------------------Unicode (source, ' UTF8 ')
The packaged compression program uses a 7zip call to
7z a-tzip Packaging to a file needs to be packaged in the directory-R (-R includes subdirectories and sub-directory files)
This article is from the "Canyu's PYTHON" blog, so be sure to keep this source http://canyuexiang.blog.51cto.com/8871379/1556391
The first backup script in a concise Python tutorial