Moving folders with content

jyoung79 at kc.rr.com jyoung79 at kc.rr.com
Sat Sep 15 00:36:00 EDT 2012


Hello,

I am working in both OS X Snow Leopard and Lion (10.6.8 and 10.7.4).  
I'm simply wanting to move folders (with their content) from various 
servers to the hard drive and then back to different directories on the 
servers.

I want to be careful not to remove any metadata or resource forks from 
the files in the directories.  I did a bit of researching on shutil, and 
looks like it is similar to using "cp -p" and copystat(), which I believe 
will keep the resource fork, etc.

Here's the code I came up with.  I'm curious if anyone finds fault with 
this, or if there's a better way to do this?

Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import os
>>> import shutil
>>> 
>>> p1 = os.path.expanduser('~/Desktop/IN/Test/')
>>> p2 = os.path.expanduser('~/Desktop/OUT/Test/')
>>> 
>>> if os.path.exists(p2): shutil.rmtree(p2)
... 
>>> shutil.copytree(p1, p2)
>>> shutil.rmtree(p1)
>>> 

Thanks!

Jay




More information about the Python-list mailing list