[Tutor] Move files to a new directory with matching folder names

Danny Yoo dyoo at hashcollision.org
Thu May 22 02:30:50 CEST 2014


On Wed, May 21, 2014 at 5:25 PM, questions anon
<questions.anon at gmail.com> wrote:
> I have files contained separately in folders labelled by years and months
> and I would like to copy them into another directory where they have
> matching folder names of years and months.
> I can do this for one folder at a time (see below) but I want it to be able
> to go through all the folders (2002/01,2002/02.....2012/11,2012/12) and copy
> files from one directory to another directory with matching subdir names.


Side note: do you have a name, or is your first name truly Questions?


shutil contains a function for recursively copying entire trees.  I
think it's called copytree().  Checking...  ok, found it.

    https://docs.python.org/3/library/shutil.html#shutil.copytree

Would this be suitable for your situation?


More information about the Tutor mailing list