stat doesn't work!

P

Paulo Pinto

I am doing an application that needs to
know when it is manipulating symbolic links.

But it is failing to reckognize them.

If I run the following code:

<code>
import sys
import os
from stat import *

mode = os.stat(sys.argv[1])[ST_MODE]
if S_ISLNK(mode):
print 'File is a link'
else:
print 'Just a normal file'
</code>


I will alway get the 'Just a normal file'
message even though I am using a symbolic
link as argument.

I've done the same example in Perl and in
bash and it works.

Could this be a bug in my Python version
(2.2.2) or I am doing something wrong ?

Thanks in advance,
Paulo Pinto
 
D

Donn Cave

I am doing an application that needs to
know when it is manipulating symbolic links.

That's a special case, and therefore you have
to use a special version of stat(). stat()
will follow the link, so you get the original
file. lstat() will report the link itself.

Donn Cave, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top