#coding =utf-8import Sys,datetime,time,os,os.path,stat,rerepattern = Re.compile (R '. *[\.] {1} ([^\.] +) ' Def changefiletime (Path, CTime): For parent,dirnames,filenames in Os.walk (path): For dirname in Dirnames: Changefiletime (Os.path.join (parent,dirname), ctime) for filename in filenames:match = Repatte Rn.match (filename) If Match:filetype = Match.Groups () [0] if filetype = = ' h ' or F Iletype = = ' c ' or filetype = = ' cpp ' or filetype = = ' hpp ' or filetype = = ' inl ': name = Os.path.join (pare Nt,filename) st = Os.stat (name) timestamp = St[stat. St_mtime] if timestamp > ctime:date = Datetime.datetime.fromtimestamp (timest AMP) os.utime (name, (St[stat). St_atime], CTime)) Print name, ' Modify Time: ', Date.strftime ('%y-%m-%d%h:%m:%s ') if __name__ = = ' __m Ain__ ': If Len (SYS.ARGV) < = 1:print "Useage:chgfiletime path" sys.exit (0) changefiletime (sys.argv[1], time.time ())
Adjust catalog file Timestamp script python