renaming files in OS X

Philip Semanchuk philip at semanchuk.com
Wed Apr 20 17:35:29 CEST 2011


On Apr 20, 2011, at 10:02 AM, <jyoung79 at kc.rr.com> <jyoung79 at kc.rr.com> wrote:

> Hello,
> 
> I'm considering using os.rename or shutil for renaming 
> files on OS X (Snow Leopard).  However, I've read that 
> shutil doesn't copy the resource fork or metadata for 
> the files on OS X.  I'm not sure about os.rename though.  
> I need to keep the resource fork and metadata.  Is it 
> better if I just use os.system('mv …') or is os.rename 
> safe to use?

Hi Jay,
I don't know if os.rename() does what you want, but why don't you try a simple test and find out? Surely an empirical test is at least as useful as an answer from someone like me who may or may not know what he's talking about. =)

The OS X command xattr  shows whether or not a file has extended attributes, which are what I think you're referring to when you say "metadata". xattr is written (badly) in Python; on my system it lives in /usr/bin/xattr-2.6

You might also find this helpful:
http://jonsview.com/mac-os-x-resource-forks


Hope this helps
Philip


More information about the Python-list mailing list