perl to python

Andrew Bennetts andrew-pythonlist at puzzling.org
Thu May 13 08:42:32 EDT 2004


On Thu, May 13, 2004 at 06:06:23AM +0000, Andrew Dalke wrote:
> 
> Here's one for you.  I had several mailbox files arranged like
>   Inbox.mbox/mbox
>   Send.mbox/mbox
>   OBF&BOSC.mbox/mbox
>   Work Email.mbox/mbox
> 
> I wanted to raise the "*/mbox" files one directory so that
>   Inbox.mbox/mbox    --becomes--> Inbox.mbox
> 
[...]
> 
> Trying doing that sanely with any programming language expressed
> all on the command-line.  No credit if you can't handle the '&' and space.

You can do it in one-line with sh:

    for d in *.mbox ; do mv "${d}/mbox" ".${d}" ; rmdir "${d}" ; mv ".${d}" "${d}" ; done

Or more readably:

    for d in *.mbox ; do
        mv "${d}/mbox" ".${d}"
        rmdir "${d}"
        mv ".${d}" "${d}"
    done

That doesn't look particularly insane to me.  In fact, it looks quite like
the Python version...

-Andrew.





More information about the Python-list mailing list