Mega Code Archive

 
Categories / Python Tutorial / File
 

The stat Module

import os, sys from stat import * sName = "test.txt" if os.access( sName, os.F_OK ) == False :     print "That file name doesn't exist!"     exit() sStat = os.stat( sName ) mMode= sStat[ST_MODE] if S_ISDIR(mMode) :     print "The path is a directory" elif S_ISREG(mMode) :     print "The path is a file" else :     print "I have no idea what the path is" userID = sStat[ST_UID] print str(userID) fSize = sStat[ST_SIZE] print str(fSize) accessTime = sStat[ST_ATIME] print str(accessTime) modTime = sStat[ST_MTIME] print str(modTime)