[Tutor] Move all files to top-level directory

Dotan Cohen dotancohen at gmail.com
Tue Apr 13 10:36:14 CEST 2010

>> I use this one-liner for moving photos nested a single folder deep
>> into the top-level folder:
>> find * -name "*.jpg" | awk  -F/ '{print "mv "$0,$1"-"$2}' | sh
> You could miss out the awk and use the exec option of find...
> Or miss out the shell and use the system() function of awk.

The truth is that is not really my code, I modified it from something
that I found. I really want to code my own, and to understand what I
am doing. I'd rather use a real language for it, not a scripting
language as I want the knowledge to apply as generally as possible.

> You won't easily get a one liner to do the same in Python but you
> can do the same things using the glob, subprocess, shutil, os and path
> modules. In particular look at the os.walk and the shutil.move functions.

I am not looking for a one-liner. But thanks for clarifying.

> In addition to the module documentation you will find examples and
> description of both in the Using the OS topic of my tutorial.

I will read that. I did see your site once, I even bookmarked it. I
will go over it thoroughly! I actually have some comments about the
site, would you like them in private mail if you are interested?


Dotan Cohen


More information about the Tutor mailing list