#!/usr/bin/env python# -*- coding: utf-8 -*-'''Created on 2015年4月16日@author : Administrator''''''import os,time print time.ctime(os.path.getmtime(r"C:\aa\bb.txt"))此脚本的作用:1:比较文件是否发生变化,把发生变化的目录抓出来,放到临时备份目录2:把临时存放的目录压缩3:删除临时存放目录里边的文件'''import os,datetimeimport shutilimport os,os.pathimport zipfileimport timefrom os.path import join,getsizestart_time=time.strftime('%Y-%m-%d') #获取系统的时间copyFileCounts = 0 start_time_a=start_time+' '+'17:00:00'start_time_b=start_time+' '+'18:00:00''''比较文件是否发生update,改变的文件抓出来说明:1:base_dir源目录2:remote_dir临时存放目录'''def compare(base_dir,remote_dir): list = os.listdir(base_dir) filelist = [] for i in range(0, len(list)): path = os.path.join(base_dir,list[i]) if os.path.isfile(path): filelist.append(list[i]) for i in range(0, len(filelist)): path = os.path.join(base_dir, filelist[i]) if os.path.isdir(path): continue timestamp = os.path.getmtime(path) print timestamp ts1 = os.stat(path).st_mtime print ts1 date = datetime.datetime.fromtimestamp(timestamp) print list[i],' 最近修改时间是: ',date.strftime('%Y-%m-%d %H:%M:%S') #if time.strftime('%Y-%m-%d'+' '+'09:00:00')0: zip_dir(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure',r'F:\nn\haha.zip') if filesize2>0: zip_dir(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZJ_fimesure',r'F:\nn\hehe.zip') ''' 1 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure\afflx') ''' 2 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure\caisse') ''' 3 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure\emboutissage') ''' 4 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure\liaisonsol') ''' 5 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure\ouvrants') ''' 6 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZH_fimesure\units') ''' 7 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZJ_fimesure\caisse') ''' 8 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZJ_fimesure\emboutissage') ''' 9 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZJ_fimesure\liaisonsol') ''' 10 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZJ_fimesure\ouvrants') ''' 11 ''' file_delete(r'D:\CFT_DATA\LIVE\LOCAL\Metrolog\temple\XZJ_fimesure\units')