473,399 Members | 2,146 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,399 software developers and data experts.

Walking The Right Path

Ah yes, moral philosophy and python all come together... Er, that is to day:

Imagine you have this situation on a *nix filesystem:

Symlink A: /foo -/usr/home
Symlink B: /bar -/foo/username
If I do this:

import os
print os.path.realpath("/bar")

I get this (as one would expect):

/usr/home/username

However, what if I want to get back the result in this form:

/foo/username
IOW, is there a way to return a symlink-based path which contains
the symlink pointer as is was *defined* not as it expands?
TIA,
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Jan 8 '07 #1
5 1217
Tim Daneliuk napisal(a):
Ah yes, moral philosophy and python all come together... Er, that is to day:

Imagine you have this situation on a *nix filesystem:

Symlink A: /foo -/usr/home
Symlink B: /bar -/foo/username
If I do this:

import os
print os.path.realpath("/bar")

I get this (as one would expect):

/usr/home/username

However, what if I want to get back the result in this form:

/foo/username
IOW, is there a way to return a symlink-based path which contains
the symlink pointer as is was *defined* not as it expands?
One way (but very ugly):
print os.path._resolve_link('/bar')

Jan 8 '07 #2
Jakub Stolarski wrote:
Tim Daneliuk napisal(a):
>Ah yes, moral philosophy and python all come together... Er, that is to day:

Imagine you have this situation on a *nix filesystem:

Symlink A: /foo -/usr/home
Symlink B: /bar -/foo/username
If I do this:

import os
print os.path.realpath("/bar")

I get this (as one would expect):

/usr/home/username

However, what if I want to get back the result in this form:

/foo/username
IOW, is there a way to return a symlink-based path which contains
the symlink pointer as is was *defined* not as it expands?

One way (but very ugly):
print os.path._resolve_link('/bar')
Yup, that does just what I want. By why, pray tell, do you consider it
ugly ...?
--
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Jan 8 '07 #3
Tim Daneliuk wrote:
Jakub Stolarski wrote:
>Tim Daneliuk napisal(a):
>>IOW, is there a way to return a symlink-based path which contains
the symlink pointer as is was *defined* not as it expands?

One way (but very ugly):
print os.path._resolve_link('/bar')

Yup, that does just what I want. By why, pray tell, do you consider it
ugly ...?

Whoops - that doesn't do it either. If I have this:

/foo -/usr/bar
/usr/bar -/usr1/bar

Then realpath or _resolve_link both return "/usr1/bar" when given "/foo"
(when what I want is "/usr/bar"). There is obviously some underlying
OS support to do this (in this case FreeBSD 4.x) because 'ls' shows
things as I prefer them - i.e. Links are shown as assigned not how they
actually resolve...
--
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Jan 8 '07 #4
Tim Daneliuk wrote:
IOW, is there a way to return a symlink-based path which contains
the symlink pointer as is was *defined* not as it expands?
os.readlink()

Peter
Jan 8 '07 #5
Peter Otten wrote:
Tim Daneliuk wrote:
>IOW, is there a way to return a symlink-based path which contains
the symlink pointer as is was *defined* not as it expands?

os.readlink()

Peter
Thanks - I couldn't find it because it was right in front of my nose :)
--
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Jan 8 '07 #6

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

Similar topics

2
by: Who Cares | last post by:
Okay, this may be a bit of a newbie question but I could really use some help. I want to write a set of routines that will read in the contents of XML files. I'll be reading the tag names,...
0
by: Chris Lyon | last post by:
I handle a lot of audio files of different formats, which live in a directory tree. WAV files in a wav directory, AIFF's in an AIFF directory next to the wav directory and mp3's in an MP3 directory...
4
by: Jim Bancroft | last post by:
Sorry for the basic nature of this question. I know XSL can do this, but I don't recall a good method... Say I have an xml structure like this: <folder_structure> <folder name="folder1">...
1
by: Thierry Lam | last post by:
I'm trying to use the os.walk() method to search all the directory from a root directory and display their contents. For example, I want my output to be like the following: directoryA...
5
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
1
by: Zachary Hartnett | last post by:
I was trying to write a routine this morning that would open a given assembly, walk the inheritance tree of classes in the assembly, and provide a list of classes in the assembly that inherit from...
5
by: TrulyUnusualdotcom | last post by:
I'm reading PHP & MySQL for Dummies 2nd edition...ya ya I know..lame. Anyway I got to the part about walking through an array and I just can't seem to figure out what this would be used for. What...
8
by: Ben Hallert | last post by:
Hi guys! I'm working on a little javascriptlet/greasemonkey script, and I've run into a challenge that I think can be solved with walking the DOM, but I feel like I'm kludging my way through and...
2
by: Evan Carmi | last post by:
hi, i am creating a program to go through a directory structure recursively (including directories below it) and move all files that end in .msf to a directory above the current level. the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
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...

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.