#扫描一个目录下的详细文件列表,包括:文件名,创建时间,最后修改时间,文件大小。
#把得到的文件信息存入日志文件中(*.log)
#codes
import os,time
from stat import *
#输入存入日志的文件名
logName = raw_input('Input the name of log:')
log=file(logName,'w')
#递归遍历文件
def walktree(top, callback):
for log in os.listdir(top):
pathname = os.path.join(top, log)
mode = os.stat(pathname)[ST_MODE]
if S_ISDIR(mode):
# It's a directory, recurse into it
walktree(pathname, callback)
elif S_ISREG(mode):
# It's a file, call the callback function
callback(pathname)
else:
# Unknown file type, print a message
print 'Skipping %s' % pathname
def visitfile(file):
size = os.path.getsize(file)
mt = time.ctime(os.stat(file).st_mtime);
ct = time.ctime(os.stat(file).st_ctime);
print 'visiting', mt ,ct,size, file
log.write(mt+'/t'+ct+'/t'+'/t' +str(size) + '/t'+'@'+file+'*'+'/n')
if __name__ == '__main__':
#walktree(sys.argv[1], visitfile)
walktree('.', visitfile)