backup_ver1.py
来自「Python 实用例程」· Python 代码 · 共 27 行
PY
27 行
# Filename: backup_ver1.py
import os
import time
import sys
sys.path.append('C:\\program files\\winrar')
# 1. The files and directories to be backed up are spectified in a list.
source = ['E:\\AIMAPythonCodes\\PythonLearning\\*.*', 'E:\\AIMAPythonCodes\\*.py'] # Windows
# 2. The backup must be stored in main backup directory
target_dir = 'E:\\DVDTEMp\\'
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
# 5. We use the winrar comand line
zip_command = "winrar a %s %s"%(target, ' '.join(source))
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
print zip_command
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?