Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3743

Re: renaming files in OS X

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'though.': 0.07; 'wrapper': 0.07; 'attribute': 0.09; 'attributes,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'rename': 0.09; 'subject:files': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'from:addr:acm.org': 0.16; 'out?': 0.16; 'preserved': 0.16; 'received:198.144': 0.16; 'renames': 0.16; 'semanchuk': 0.16; 'shutil': 0.16; 'case.': 0.16; "he's": 0.19; 'command': 0.19; 'handles': 0.20; 'version': 0.25; "i'm": 0.26; "doesn't": 0.28; 'about.': 0.29; 'least': 0.30; 'use?': 0.31; 'does': 0.31; 'however,': 0.31; 'to:addr:python- list': 0.32; "i've": 0.33; 'received:198': 0.33; 'someone': 0.33; 'test': 0.33; 'copying': 0.34; 'using': 0.34; 'header:X -Complaints-To:1': 0.34; 'file': 0.35; 'header:User-Agent:1': 0.35; 'surely': 0.35; 'none': 0.36; 'shows': 0.36; 'system.': 0.37; 'useful': 0.37; '20,': 0.38; 'apr': 0.38; 'but': 0.38; 'files': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'header:Mime-Version:1': 0.39; 'works': 0.40; 'header:Received:5': 0.40; 'philip': 0.60; 'simple': 0.60; 'extended': 0.64; 'safe': 0.65; 'want,': 0.72; 'article': 0.75; '(snow': 0.84; '16:30': 0.84; 'empirical': 0.84; 'metadata': 0.84; 'well:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Deily <nad@acm.org>
Subject Re: renaming files in OS X
Date Wed, 20 Apr 2011 12:43:44 -0700
References <20110420140240.534UB.124867.root@cdptpa-web13-z01> <280CB56A-89B8-4D62-9374-D769B3ACFEBB@semanchuk.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host baybryj.net
User-Agent MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.667.1303328645.9059.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 82.94.164.166
X-Trace 1303328645 news.xs4all.nl 81481 [::ffff:82.94.164.166]:43586
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3743

Show key headers only | View raw


In article <280CB56A-89B8-4D62-9374-D769B3ACFEBB@semanchuk.com>,
 Philip Semanchuk <philip@semanchuk.com> wrote:
> On Apr 20, 2011, at 10:02 AM, <jyoung79@kc.rr.com> <jyoung79@kc.rr.com> 
> wrote:
> > 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?

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.

> 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, 

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

-- 
 Ned Deily,
 nad@acm.org

Back to comp.lang.python | Previous | Next | Find similar


Thread

Re: renaming files in OS X Ned Deily <nad@acm.org> - 2011-04-20 12:43 -0700

csiph-web