Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Moving folders with content

Reply
Thread Tools

Moving folders with content

 
 
Guest
Posts: n/a
 
      09-15-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 565 (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

 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      09-15-2012
On Sat, 15 Sep 2012 04:36:00 +0000, jyoung79 wrote:

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


I don't think so. The shutil documentation says:

Warning

Even the higher-level file copying functions (copy(), copy2()) can’t
copy all file metadata.

On POSIX platforms, this means that file owner and group are lost as well
as ACLs. On Mac OS, the resource fork and other metadata are not used.
This means that resources will be lost and file type and creator codes
will not be correct. On Windows, file owners, ACLs and alternate data
streams are not copied.

The macostools module has functions which can copy the resource fork, but
they aren't available in 64-bit builds and have been removed in Python 3.0.

 
Reply With Quote
 
 
 
 
Hans Mulder
Guest
Posts: n/a
 
      09-15-2012
On 15/09/12 10:00:16, Nobody wrote:
> On Sat, 15 Sep 2012 04:36:00 +0000, jyoung79 wrote:
>
>> 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.

>
> I don't think so. The shutil documentation says:
>
> Warning
>
> Even the higher-level file copying functions (copy(), copy2()) can’t
> copy all file metadata.
>
> On POSIX platforms, this means that file owner and group are lost as well
> as ACLs. On Mac OS, the resource fork and other metadata are not used.
> This means that resources will be lost and file type and creator codes
> will not be correct. On Windows, file owners, ACLs and alternate data
> streams are not copied.
>
> The macostools module has functions which can copy the resource fork, but
> they aren't available in 64-bit builds and have been removed in Python 3.0.


You may want to use the subprocess module to run 'ditto'. If
the destination folder does not exist, then ditto will copy MacOS
specific aspects such as resource forks, ACLs and HFS meta-data.

If the destination already exists, then ditto will copy file
contents, but not modify mode, ownership or ACLs of existing
folders inside the destination folder.

See the manual page for details.


Hope this helps,

-- HansM


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Moving folders with content Python 4 09-16-2012 08:53 PM
Re: Moving folders with content Laszlo Nagy Python 0 09-15-2012 06:36 AM
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted ASP .Net 0 01-06-2008 04:45 AM
Syncing POP folders with IMAP folders Rich Computer Support 1 02-12-2004 09:36 PM



Advertisments