473,657 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(filePat h)[ST_MODE]

print 'Find using os.path : ',os.path.islin k(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 ?
Aug 28 '08 #1
5 3595
sa****@gmail.co m 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

Aug 28 '08 #2
On Aug 28, 3:11*pm, Christian Heimes <li...@cheimes. dewrote:
sas...@gmail.co m 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
Do you mean the following is deprecated ?
http://docs.python.org/lib/module-stat.html

From the documentation -

S_ISLNK( mode)
Return non-zero if the mode is from a symbolic link.

Thanks
-Saswat
Aug 28 '08 #3
saswat wrote:
On Aug 28, 3:11 pm, Christian Heimes wrote:
>sas...@gmail.c om 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().

Do you mean the following is deprecated ?
http://docs.python.org/lib/module-stat.html
From the documentation -

S_ISLNK( mode)
Return non-zero if the mode is from a symbolic link.
No, it means that os.stat follows the symbolic link and gives stat
information for the file that the symbolic link points to, which is
*not* a symbolic link. Like the documentation for lstat says: "Like
stat(), but do not follow symbolic links." But why not just use
os.path.islink?

-Miles
Aug 29 '08 #4
sa****@gmail.co m wrote:
Do you mean the following is deprecated ?
http://docs.python.org/lib/module-stat.html
>>From the documentation -

S_ISLNK( mode)
Return non-zero if the mode is from a symbolic link.
As that page states, that's a function used to interpret a mode flag
returned by os.stat, os.fstat, or os.lstat. It obviously won't give you
the result you're looking for if you use a stat function that *follows*
symbolic links.

</F>

Aug 29 '08 #5
On Aug 28, 10:20*pm, Fredrik Lundh <fred...@python ware.comwrote:
sas...@gmail.co m wrote:
Do you mean the following is deprecated ?
http://docs.python.org/lib/module-stat.html
>From the documentation -
S_ISLNK( mode)
* * Return non-zero if the mode is from a symbolic link.

As that page states, that's a function used to interpret a mode flag
returned by os.stat, os.fstat, or os.lstat. *It obviously won't give you
the result you're looking for if you use a stat function that *follows*
symbolic links.

</F>
Thank you Fredrick and Miles,

stat() is on the actual file and not on the symlink. That explains.

-Saswat
Aug 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4690
by: Rene' Nielsen | last post by:
Context: Running Windows 2003 Server on an intranet. A web is configured with an anonymous access account that is a domain account that has been granted the desired access to a file on another server in the domain. An asp page in the web attempts to open (or any other access) the remote file and fails. Auditing is enabled on the remote system and for the file in question but no access denied records are being recorded.
6
8452
by: Rolf Schroedter | last post by:
(Sorry for cross-posting). I need to access large files > 2GByte (Linux, WinXP/NTFS) using the standard C-library calls. Till today I thought I know how to do it, namely for Win32: Use open(), read(), _itelli64(), _lseeki64() with type __int64 Linux/Cygwin: #define _FILE_OFFSET_BITS 64 Use open(), read(), lseek() with type off_t
1
3212
by: Anoop | last post by:
Hi All Please tell me how to check the existence of a file and the read permission to the file using python script Thanks for ur inputs Anoop
19
9264
by: jeremyz | last post by:
Hi all, I am not a developer, but I work with several and am posting this for them. We are trying to determine whether it is possible to check the size of a file before a user uploads it. Everything I've read suggests that this is impossible (or at least very difficult) in PHP, and this makes sense for a server-side language. What gives me pause, however, is the fact that when a user tries to upload a file larger than the max file...
0
266
by: Daniel | last post by:
What do FTP servers do when file send fails durring a file upload? Are partial files ever written? does ftp protocol cover this?
6
3035
by: Vic Spainhower | last post by:
Hello, I am trying to do a FTP file upload which works fine on my localhost but on my ISP server it fails. I can't seem to find where I can go to find the specific cause of the failure. In both cases the file is being transmitted to the same FTP server and using the same PHP script so it shouldn't be a file size or login credentials problem. Could someone please help me out and give me some ideas what is wrong. I would really...
1
1357
by: brett | last post by:
If I participate in a forum that doesn't have any way to watch threads or any type of RSS, I could get the filesize of the thread I want to watch. When the filesize changes, I know there is a new post. Are there any reasons why this won't work? If the above will work, how is it different from using RSS? Or can RSS support just a regular page (no XML for RSS available)? Thanks, Brett
1
1107
donilourdu
by: donilourdu | last post by:
Hi I am Doni. Currently doing a website.It contains lots of images. While loading page I need to check wether the images are ailable or not. All the images are in separate server. i.e. My Code in Server A . My images are in Server B , Server C ,..... (I having same images in two different servers. If one fails means I need to go for next Vice versa). So Here I need code to cheack that location or image is avilable in that...
0
1181
by: =?Utf-8?B?VmlqYXkgR2FuZXNo?= | last post by:
We are using a logo by calling Image.FromFile(). Based on that we are opening a report (using a 3rd party Report generation tool) and without closing the report, We are trying to change the logo by calling File.Copy, at that time application fails to copy and throws exception. The report is somehow locking locking the logo file, and that's why the copy into the logo file fails. But how do we disassociate the logo file from the created...
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.