473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

stat doesn't work!

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
3 1607
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steven T. Hatton | last post by:
I found the following two statements in the file linked below: struct stat st; stat(fileName.c_str(), &st); http://websvn.kde.org/branches/work/kdevelop4-parser/main.cpp?rev=420247&view=markup...
5
by: diadia | last post by:
#include <sys/types.h> #include <sys/stat.h> #include "ctype.h" #include <stdio.h> int estimateLen(struct stat buf, FILE *fp) { size_t _size = buf.st_size / 4;
3
by: David Bear | last post by:
I'm trying to use os.chmod and am refered to the stat module. Is there are explanation of: * S_ISUID * S_ISGID * S_ENFMT * S_ISVTX * S_IREAD * S_IWRITE * S_IEXEC
2
by: cedarson | last post by:
I am writing a program and have been instructeed to use the 'fseek', 'ftell', and 'stat' functions, however, after looking in the online manual for each of these, I am still unsure on how to use...
6
by: one2001boy | last post by:
Hello, I tried to find the access time of a file using stat() function. but the following C code in windows vc.net 2003 always give the same access time. the same code works correctly in linux...
6
by: Hansen | last post by:
Hi Group, I've made a statistic module for our framework, and have put it in a namespace called stat (which resides in a namespace called dao) My problem is that now the compiler thinks that it...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
2
by: Alona | last post by:
Hi All, stat fails on a 2GB file with errno=EOVERFLOW. Is there a way to run stat() on a large file? Thanks, Alona
3
by: Deniz Dogan | last post by:
Hello. I have a question regarding the st_mode field of the "stat" struct in sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and S_IRWXO flags to mask the mode_t value into human...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.