S
saswat
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 ?
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 ?