Reputation: 2047
I am trying to check whether a file is soft link or regular file. But when i am checking a soft-link using os.path.isfile and os.path.link both functions return True.
In [34]: os.path.isfile('/bin/lessfile')
Out[34]: True
In [35]: os.path.islink('/bin/lessfile')
Out[35]: True
In [36]: ll /bin/lessfile
lrwxrwxrwx 1 root 8 Apr 29 15:22 /bin/lessfile -> lesspipe*
Is there anything wrong in my code? or i am missing any arguments?
Upvotes: 1
Views: 3820
Reputation: 94838
islink
returns True because /bin/lessfile is a link. isfile
returns True because the link points to file. Create a link pointing to a directory and test — isfile
will return False.
Upvotes: 4