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 [mailto:nodum@csc.com]
Sent: Thursday, May 14, 2009 7:23 AM
To: jython-users@lists.sourceforge.net
Subject: [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