renaming files in OS X

jyoung79 at kc.rr.com jyoung79 at kc.rr.com
Wed Apr 20 22:06:11 CEST 2011


> In article <280CB56A-89B8-4D62-9374-D769B3ACFEBB at semanchuk.com>,
>  Philip Semanchuk <philip at semanchuk.com> wrote:
> > On Apr 20, 2011, at 10:02 AM, <jyoung79 at kc.rr.com> <jyoung79 at kc.rr.com> 
> > wrote:
> > > I'm considering using os.rename or shutil for renaming 
> > > files on OS X (Snow Leopard)…

> os.rename() is a simple wrapper around the standard rename system call 
> (man 2 rename) so it has the same semantics.  Extended attributes, 
> including resource forks, are preserved by rename(2).  Note that the 
> system call only works for renames within one file system.  The mv(1) 
> program handles cross-system renames by copying and unlinking and the 
> Apple-supplied version does copy extended attribute metadata in that 
> case.  As documented, none of the shutil copy functions do that.

> > The OS X command xattr  shows whether or not a file has extended attributes, 

> The 'ls -l' command does as well:

> $ ls -l a.jpg
> -rw-r--r--@  1 nad  staff  2425268 Apr  4 16:30 a.jpg
> $ ls -l@ a.jpg
> -rw-r--r--@  1 nad  staff  2425268 Apr  4 16:30 a.jpg
>    com.apple.FinderInfo      32


Hi Ned,

Thanks so much for this detail!  I didn't even realize there was a standard
rename system call - it's always nice learning something new about this
system.

Again, thank you for taking the time to share your knowledge.  This is
exactly what I was looking for!

Jay



More information about the Python-list mailing list