#!/usr/bin/env python
#-*- encoding:UTF-8 -*-
import os,time,stat
fileStats = os.stat ( 'test.txt' ) # /
fileInfo = {
'Size':fileStats [ stat.ST_SIZE ], #
'LastModified':time.ctime( fileStats [ stat.ST_MTIME ] ), #
'LastAccessed':time.ctime( fileStats [ stat.ST_ATIME ] ), #
'CreationTime':time.ctime( fileStats [ stat.ST_CTIME ] ), #
'Mode':fileStats [ stat.ST_MODE ] #
}
#print fileInfo
for field in fileInfo: #
print '%s:%s' % (field,fileInfo[field])
for infoField,infoValue in fileInfo:
print '%s:%s' % (infoField,infoValue)
if stat.S_ISDIR ( fileStats [ stat.ST_MODE ] ): #
print 'Directory. '
else:
print 'Non-directory.'
if stat.S_ISREG( fileStats [ stat.ST_MODE ] ): #
print 'Regular file.'
elif stat.S_ISLNK ( fileStats [ stat.ST_MODE ] ): #
print 'Shortcut.'
elif stat.S_ISSOCK ( fileStats [ stat.ST_MODE ] ): #
print 'Socket.'
elif stat.S_ISFIFO ( fileStats [ stat.ST_MODE ] ): #
print 'Named pipe.'
elif stat.S_ISBLK ( fileStats [ stat.ST_MODE ] ): #
print 'Block special device.'
elif stat.S_ISCHR ( fileStats [ stat.ST_MODE ] ): #
print 'Character special device.'