Hi Keith,

> So, after all that, my question is: why did you restrict the answers
> you wanted to bash (I'm not criticising that restriction, but I am
> curious)?

Terry's replied, but as a *Unix* programmer my natural inclination would
still be to first wonder if it could be done in the shell without
needing a custom program.  The shell offers such high-level tools with
I/O redirection allowing them to be easily combined, e.g. pipelines,
that "The whole is greater than the sum of its parts".

It's quicker for me to cogitate and play around a bit to come up with

    find -depth -print0 |
    xargs -r0 prename -n '1 while s#'\''([^/]*)$#$1#'

and verify it covers my particular files than it is to write

    #! /usr/bin/python

    import os

    def scan(cur):
        for entry in os.listdir(cur):
            path = os.path.join(cur, entry)
            if os.path.isdir(path):
                scan(path)

            new = entry.replace("'", '')
            if new != entry:
                new = os.path.join(cur, new)
                if os.path.lexists(new):
                    raise SystemExit, 'refusing to overwrite %s with %s' % 
(new, path)
                print path, '->', new
                os.rename(path, new)

    scan('.')

The length of what needs to be written is part of it;  not just the
typing but the inspection.  The shell's higher-level concepts give
brevity.

The shell isn't always the right fit and, as you say, filenames are a
pain if they can contain anything, but for ad hoc local use where it can
be determined that's not a problem the shell can be quick and easy.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2013-01-08 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:[email protected]
How to Report Bugs Effectively:  http://goo.gl/4Xue

Reply via email to