You can extend the use of glob in David's example like so: \*\*

From: Nicolai Odum []
Sent: 14 May 2009 16:23
To: David Handy
Subject: Re: [Jython-users] Howto merge 2 folder into a new folder

Hey David

Thx for the reply

I forgot (sorry) to say that folder1 and folder2 contains subfolders. And if I remember correctly then copy command expect the folder to exist already.

You got a good idea on how to solve that problem (in a elegant way)
  Nicolai Marck ědum

David Handy <>

14-05-2009 17:07

Nicolai Odum/SCA/SC/CSC@CSC, "" <>
RE: [Jython-users] Howto merge 2 folder into a new folder

I like the glob module.
import glob
import shutil
for filename in glob.glob('/tmp/folder1/*') + glob.glob('/tmp/folder2/*'):
shutil.copy(filename, '/tmp/folder3')
David H
From: Nicolai Odum []
Thursday, May 14, 2009 7:23 AM
[Jython-users] Howto merge 2 folder into a new folder



The pledge:

Howto in a platform independent copy files from 2 folders with a unknown number of files into a new folder in jython

like (in unix)

cp /tmp/folder1/* /tmp/folder3

cp /tmp/folder2/* /tmp/folder3

The turn:

(I use shutil)

shutil.copytree('/tmp/folder1/' ,  '/tmp/folder3')

shutil.copytree('/tmp/folder2/' ,  '/tmp/folder3')

The presitge:

Well not very fancy actually - I get a exception on the second call to copytree because copytree demands that target folder doesn't exsists. (I can't understand *why* it demands that)

shutil.copy doesn't accept the input to be a folder so that can't be used either

How do I turn this into a good prestige :-D

 Nicolai ědum