Need help with shutils.copytree

S

Steven W. Orr

I have a 'master' directory and a collection of 'slave' dirs. I want the
master to collect all of the stuff in the slave dirs.

The slaves all look like this,

..
|-- slaveX
| `-- archI
| | `-- distJ
| | | ` -- FILE

Where the different slaveX dirs may contain multiple occurrences of archI and
distJ, but across all slaveX dirs, there will only be one *unique* instance of
FILE in archI and distJ.

Here's an example: Given slave[1234], arch1 and arch2, and dist1 and dist2, I
want master to end up looking like this:

..
|-- master
| `-- arch1
| | ` -- dist1
| | | ` -- FILE
| `-- arch1
| | ` -- dist2
| | | ` -- FILE
| `-- arch2
| | ` -- dist1
| | | ` -- FILE
| `-- arch2
| | ` -- dist2
| | | ` -- FILE

etc...


In bash, I might use cpio passthrough mode and say something like:

master=$path_to_master
for slave in ${slaves}
do
pushd $slave
find . -print | cpio -pdum $master
popd
done

but I'm having a hard time trying to get this functionality in python. (I'm
trying to avoid writing a subprocess.)

I tried using shutil.copytree with a try / except that does a pass on OSError
(which is what gets raised when trying to create a dir that already exists).
No joy there. I also tried an ignore function that always returns ().

Someone must have done this before. Any suggestions / pointers are much
appreciated.

(I hope this was clear to read.)

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top