[Tutor] How can I copy files recursively?

Alan Gauld alan.gauld at freenet.co.uk
Tue Jul 11 22:03:13 CEST 2006


> subfolders. I'd like to write a quick script to move (not copy) all 
> the mp3
> files in those folders into a single destination folder. I was 
> thinking I
> could do it easily from the linux command line (cp -r copies the 
> subfolders
> out as well) but I can't figure out how to do it. Is there an easy 
> way to
> achieve this using Python? I am assuming this would be something 
> Python was
> designed to make easy..

Things which are easy in the shell are usually less easy in Python.
In your case a simple cp -r will copy the files and an rm -rf will
delete the originals.

Or you could just use mv on the top level folder.

However the OS topic in my tutor provides all the bits you need
to write a python script if you really need to.

Alan G. 




More information about the Tutor mailing list