saswat@gmail.com | 28 Aug 23:52

Checking if the file is a symlink fails


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 ?

--
http://mail.python.org/mailman/listinfo/python-list

(Continue reading)

Christian Heimes | 29 Aug 00:11
Favicon

Re: Checking if the file is a symlink fails

saswat <at> gmail.com wrote:
> File symLinkTest is a symbolic link.
> 
> Why S_ISLNK(mode) returns False and S_ISREG(mode) returns True ?

Because you are using os.stat() instead of os.lstat().

http://docs.python.org/lib/os-file-dir.html

Christian

--
http://mail.python.org/mailman/listinfo/python-list


Gmane