#将原有文件备份,并清空原文件内容
#!/usr/bin/env/ python
#coding=utf-8
import shutil
import os
import sys
from time import strftime, localtime
#from datetime import timedelta, date
import calendar
#文本备份接口
def BackupData(src_path, src_fileName, dst_path):
#获取当前格式化时间
year = strftime("%Y",localtime())
mon = strftime("%m",localtime())
day = strftime("%d",localtime())
hour = strftime("%H",localtime())
min = strftime("%M",localtime())
sec = strftime("%S",localtime())
#处理源路径和目标路径
#src_path = os.getcwd()
#src_path = sys.path[0]
src = src_path + '/' + src_fileName
dst = dst_path + '/' + year + '_' + mon + '_'+ day + '_'+ hour + min + sec + '.dat'
#开始备份
shutil.copyfile(src, dst)
#清空原有数据
#os.remove(src)
fileTmpHandler = file(src, 'w')
fileTmpHandler.close
# 测试部分
if __name__ == '__main__':
srcPath = sys.path[0] + '/data'
BackupData(srcPath, 'hottopic.dat', srcPath)