Checking if the file is a symlink fails

saswat at gmail.com saswat at gmail.com
Thu Aug 28 17:55:54 EDT 2008


check if file is a symlink
Here is a small piece of code:

import os
from stat import *

filePath = "/home/xyz/symLinkTest"
mode = os.stat(filePath)[ST_MODE]

print 'Find using os.path : ',os.path.islink(filePath)

print 'Find using mode :', S_ISLNK(mode)
print 'Is this a regular file : ' S_ISREG(mode)

Output :
---------

Find using os.path : True
Find using mode : False
Is this a regular file :  True


File symLinkTest is a symbolic link.

Why S_ISLNK(mode) returns False and S_ISREG(mode) returns True ?





More information about the Python-list mailing list