By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,270 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,270 IT Pros & Developers. It's quick & easy.

stat doesn't work!

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mon, Feb 09, 2004 at 05:10:31PM +0100, Paulo Pinto wrote:
I am doing an application that needs to
know when it is manipulating symbolic links.


try os.lstat.
import os
from stat import *
S_ISLNK(os.stat("/proc/self").st_mode) 0 S_ISLNK(os.lstat("/proc/self").st_mode)

1

Jeff

Jul 18 '05 #2

P: n/a
In article <c0**********@sunnews.cern.ch>,
Paulo Pinto <pa*********@cern.ch> wrote:
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, do**@u.washington.edu
Jul 18 '05 #3

P: n/a
It works now.
Thanks for your answers.

Paulo Pinto wrote:
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


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.