一段备份文件的python程序(3)
来源:互联网 发布:智能手机数据开关app 编辑:程序博客网 时间:2024/06/06 09:44
源代码如下:
#!/usr/bin/python
#Filename: backup_ver3.py
# Function: Backup files every day with comments
# Precondition:
# 1. zip tool is installed.
# 2. python is installed.
import os
import time
# 1. The files and directories to be backed up are specified in a list.
source = ['c:\\out\\workspace', 'c:\\tmp']
# 2. The backup must be stored in a main backup directory
target_dir = 'c:\\AuthLog'
# 3. The files are backed up into a zip file.
# 4. The current day is the name of the subdirectory in the main directory
today = target_dir + os.sep + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
# Take a comment from the user to create the name of the zip file
comment = input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
target = today + os.sep + now + '.zip'
else:
target = today + os.sep + now + '_' + comment.replace(' ', '_') + '.zip'
# Create the subdirectory if it isn't already there
if not os.path.exists(today):
os.mkdir(today) # make directory
print('Successfully created directory', today)
# 5. We use the zip command to put the files in a zip archive
delimiter = ' '
zip_command = '"C:\Program Files\WinRAR\WinRAR.exe" a {0} {1}'.format(target, delimiter.join(source))
print(zip_command)
# Run the backup
if os.system(zip_command) == 0:
print('Successful backup to ', target)
else:
print('Backup failed')
- 一段备份文件的python程序(3)
- 一段备份文件的python程序(1)
- 一段备份文件的python程序(2)
- 实验室的一段Python脚本 “备份文件操作”
- 实验室的一段Python脚本,根据用户指定路径来备份文件
- 第一个python程序:备份文件
- 备份文件的小程序
- 备份文件的python脚本
- 第一个自己写的python程序:windows下备份文件
- python 备份文件的小脚本
- 11.2-关于自动备份文件 Python-使用Python编写的文件备份程序
- python 备份文件
- python备份文件
- python备份文件
- Python备份文件
- Python 备份文件
- 飘逸的python - 一段统计次数程序的进化
- python读北大corpor的一段测试程序
- JavaSE第二讲:原生数据类型 Primitive Data Type
- jsp-语法学习
- python模块属性查询,help使用注意事项
- jQuery对于字符串处理
- centos 7安装pycharm
- 一段备份文件的python程序(3)
- Python的list,tuple学习
- Ubuntu 14.04安装WPS
- 欢迎使用CSDN-markdown编辑器
- 安卓开发:用本地图片路径显示图片
- 各种数据库的jdbc驱动下载及连接方式
- 京东商城总架构师刘海锋:世界上本没有架构,建设的需求多了便有了架构
- iOS自定义控件-UISearchBar
- 前端动画的bug:hover一个li,左滑进背景图,li上文字消失太快(或者说出现闪现消失)