[Tutor] How can I copy files recursively?

Dustin J. Mitchell python-tutor at v.igoro.us
Tue Jul 11 05:57:32 CEST 2006


Richard Querin wrote:
> I know this is probably a dumb question:
> 
> I've got mp3 files that are downloaded (by ipodder) into individual
> 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..

Python's not always the best with complex manipulations like that.  You
could use os.path.walk, but here's the same thing in bash:

 find $IPODDER_DIR -type f -exec mv \{} $DEST_DIR \;

Dustin


More information about the Tutor mailing list