[Pythonmac-SIG] Re: resolve alias

Christopher Smith csmith@blakeschool.org
Mon, 10 Sep 2001 11:55:08 -0500


jack@oratrix.nl writes:
>
>> Well...I created a file on the desktop, dragged an alias of it to a
>> "src" folder and fed the path to that alias to the macostools.copy(). 
>The
>> alias itself is copied to the destination folder (dst), not the 
>> original. How can I get the original to copy instead of the alias?
>> Did I misread the docs?
>
>No, you didn't misread the docs, the docs were just wrong. They've been
>fixed:
>if you copy an alias file you copy the alias file, not what it is
>pointing to.
>
OK, now it's as easy as falling off a log!  What a nice set of 
tools for working with files on the Mac :-)  Thanks for the
responses.  If anyone else is thinking about copying files 
around on the Mac with Python, here is a demo code.

####
'''
A file demonstrating how to copy a source file
to a destination file.  In this case the dst file
has the same name as the src file.  If the src
file is an alias, the alias will be resolved and
the original file will be copied.  If the reolution
is not made then the alias file itself will be 
copied.  

.copy automatically copies the creator and type
information.

cps 9/10/01
'''

import macostools,macfs

#src: file named a in folder orig on the desktop
a='Macintosh HD:Desktop Folder:orig:a'

#dst: file named a in folder pref on the desktop
b='Macintosh HD:Desktop Folder:pref:a'

#resolve alias if necessary 
afss,aIsFolder,aIsAliased=macfs.ResolveAliasFile(a)
if aIsAliased:
	a=afss

#copy src to dst
macostools.copy(a, b)

####

/c