From: Keith Hughitt on
Suppose you have two file-trees with common sub-directories but
different files that you want to merge together, e.g.

/test/
/test/a/
/test/a/file1

/test2/
/test2/a/
/test2/a/file2

You can easily merge the directories in Linux using the "cp" command:

cp -r test/* test2/

While Python provides some helpful methods for moving files and
directories around (shutil.move, shutil.copytree, etc), none of them
seem to be able to merge two directories.

I've looked around some on Google for an alternative to calling cp
directly, but so far no luck.

Any ideas?
From: Steven Howe on
Think about using the subprocess module. There are calls made just for
your. Notably (using command pydoc subprrocess.call) :
---------------------
subprocess.call = call(*popenargs, **kwargs)
Run command with arguments. Wait for command to complete, then
return the returncode attribute.

The arguments are the same as for the Popen constructor. Example:

retcode = call(["ls", "-l"])
---------------------


Steven Howe


On 04/16/2010 06:48 AM, Keith Hughitt wrote:
> Suppose you have two file-trees with common sub-directories but
> different files that you want to merge together, e.g.
>
> /test/
> /test/a/
> /test/a/file1
>
> /test2/
> /test2/a/
> /test2/a/file2
>
> You can easily merge the directories in Linux using the "cp" command:
>
> cp -r test/* test2/
>
> While Python provides some helpful methods for moving files and
> directories around (shutil.move, shutil.copytree, etc), none of them
> seem to be able to merge two directories.
>
> I've looked around some on Google for an alternative to calling cp
> directly, but so far no luck.
>
> Any ideas?
>