#-*-Coding: cp936 -*- Import OS, time # Change the time in the file attribute to '2017-1-12 00:00:00 formatting' Def formattime (localtime ): Endtime = time. strftime ("% Y-% m-% d % H: % M: % S", time. localtime (localtime )) Return endtime Def searchdir (arg, dirname, names ): For filespath in names: # Obtain the file path Fullpath = OS. path. join (dirname, filespath) # Get File Attributes Statinfo = OS. stat (fullpath) # File Size Sizefile = statinfo. st_size # Creation Time Creattime = formattime (statinfo. st_ctime) # Modification time Maketime = formattime (statinfo. st_mtime) # Browsing time Readtime = formattime (statinfo. st_atime) # Determining whether a folder or a file is used If OS. path. isdir (fullpath ): Filestat = 'dir' Else: Filestat = 'file' Open ('C: \ test.txt ', 'A '). write ('[% s] path: % s file size (B): % s creation time: % s modification time: % s browsing time: % s \ r \ n' % (filestat, fullpath, sizefile, creattime, maketime, readtime )) If _ name __= = "_ main __": Paths = "g :\\" OS. path. walk (paths, searchdir ,()) |