[Pythonmac-SIG] Carbon.File and resolving aliases

Jack Jansen Jack.Jansen at cwi.nl
Thu Jan 15 17:48:29 EST 2004


On 15-jan-04, at 0:20, Paul Donovan wrote:

> I'm trying to work out how to deal with aliases in Python 2.3 on 
> Panther. Searching the archives I came across the macfs module, but 
> the documentation says to consider it obsolete for 2.3 and use 
> Carbon.File instead. Where would I find documentation on that?
>
> The situation I'm trying to handle is very simple. I need to read a 
> file in the user's home directory which is fairly likely to be an 
> alias (it's the iTunes music library - people often put an alias to a 
> shared library in /Users/Shared so that multiple users can share the 
> same music library).
>
> My non-alias aware code is simply:
>
> 	file = os.path.expanduser('~/Music/iTunes/iTunes Music Library.xml')
>
> Any suggestions?

It's not simple, if you want to cater for aliases in the middle (which 
I assume you do). A solution would be to split file into components, 
set result to the first component apply os.path.exists() to result, if 
it doesn't exist try replacing it with 
Carbon.File.ResolveAliasFile(result) and go back to the top. If 
os.path.exists() returns true you append the next component and start 
over. Continue until you're out of components.

If you write the routine I'd be interested in adding it to the 
macostools module.
--
Jack Jansen, <Jack.Jansen at cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman




More information about the Pythonmac-SIG mailing list