1. Windows 7:
Install python2.x or 3.x,Programming LanguageNote that most of the tutorials on the Internet are 2. x.
After cmd, before running Python XXX. py, you need to set the environment variable and write the path name during Python installation to the variable value. The variable name is still the path
In my situation, the shortcut key FN + F5 is used to run the py file. The packaging fails, but Python XXX. py runs the packaging script normally in cmd,CodeAs follows:
#-*-Coding: cp936 -*-
Import OS
Import time
# Specify the name and directory of the file to be backed up in the list
Source = [R ' "D: \ Kankan" ' ]
# Back up data to the following directory
Target_dir = ' H :\\ '
# The backup file is a zip file with the file name: year, month, hour, minute, second. Zip
Target = target_dir + ' Backup ' + ' . Zip '
# Use the WinRAR command line to compress the file, provided that WinRAR is in the path of WindowsXP
Zip_command = " RAR a % S % s " % (Target, ' ' . Join (source ))
# Run this backup Program To back up
If OS. System (zip_command) = 0 :
Print ' Successful backup ' , Target
Else :
Print ' Backup failed! '
Note that when you use the RAR a command to package files or folders, make sure that the environment variables have been configured, and the path also contains the installation path of RAR, control panel-system-advanced-environment variables-System Variables
2. Linux Ubuntu
#-*-Coding: cp936 -*-
Import OS
Import time
# Specify the name and directory of the file to be backed up in the list
Source = [R ' "/Home/xiaonuo/somefile" ' ]
# Back up data to the following directory
Target_dir = ' /Home/xiaonuo/zipfile '
# The backup file is a zip file with the file name: year, month, hour, minute, second. Zip
Target = target_dir + ' Backup ' + ' . Zip '
# Use the WinRAR command line to compress the file, provided that WinRAR is in the path of WindowsXP
Zip_command = " Zip-QR % S % s " % (Target, ' ' . Join (source ))
# Run this backup program to back up data
If OS. System (zip_command) = 0 :
Print ' Successful backup ' , Target
Else :
Print ' Backup failed! '
In most Linux versions, python is installed by default. You can directly enter Python (PATH) xxx. py in the terminal to execute the prepared py code. The zip command is provided by the system and does not require multiple methods.