"Dotan Cohen" <dotanco...@gmail.com> wrote

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.

I need. I have googled file handling in Python but I simply cannot get
something to replicate the current functionality of that lovely
one-liner. What fine manual should I be reading? I am not asking for
code, rather just a link to the right documentation.

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.

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

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to