Excerpt from: http://blog.csdn.net/forandever/article/details/5711319
A python script that gets the file name and file modification time of a certain format in the specified directory and saved as a file
@for &ever 2010-07-03
Function:
Gets the file name and file modification time for the specified directory under certain rules, and saves it to the specified file
The script is as follows:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
‘‘‘
Created on 2010-7-2
@author: Forever
‘‘‘
Import glob, OS, datetime
#Windows
Filesread = r "C:/forever/logxyz-*.gif"
FileWrite = r "C:/forever/count.txt"
#Linux
#filesRead = r "/forever/logxyz-*.gif"
#fileWrite = r "/forever/count.txt"
if __name__ = = ' __main__ ':
List = Glob.glob (Filesread)
# Print List
Out=open (FileWrite, ' W ')
Out.write (' All GIF files: ')
Out.write ('/n ')
For I in list:
basename = Os.path.basename (i)
#print basename
Lastmod = Os.path.getmtime (i)
#print Lastmod
MyDate = datetime.datetime.fromtimestamp (int (lastmod))
#print mydate
Out.write (' filename: ' + basename + ' lastmod: ' + str (mydate))
Out.write ('/n ')
Out.close ()
A python script that gets the file name and file modification time of a certain format in the specified directory and saved as a file