[Tutor] Move all files to top-level directory

Steven D'Aprano steve at pearwood.info
Mon Apr 12 18:06:47 CEST 2010


On Tue, 13 Apr 2010 12:11:30 am Dotan Cohen 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
>
> I would like to expand this into an application that handles
> arbitrary nesting and smart rename, so I figure that Python is the
> language that 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. 

"Lovely"??? What on earth does it do? It's worse than Perl code!!!
*half a wink*


> What fine manual should I be reading? I am not 
> asking for code, rather just a link to the right documentation.

See the shell utilities module:

import shutil




-- 
Steven D'Aprano


More information about the Tutor mailing list