On Mon, May 01, 2017 at 10:19:02PM +1000, David wrote:
> I recommend the perl rename tool. On debian you would install this
> package:
> https://packages.debian.org/jessie/rename
i second this recommendation. the perl rename utility is great. bulk
rename via regular expression.....or ANY perl code fragment that returns
a replacement filename.
It's basically a big loop around the perl File::Rename module.
/usr/bin/rename feeds filenames into whatever script you give it and if
the filename is returned changed, it renames that filename to whatever
the returned name. if return is empty or unchanged, it doesn't get
renamed.
Most rename scripts you'll write are just one or more 's/search/replace/'
one-liner statements, but they can be a quite complicated perl script if
required.
BTW, on non-debian systems, an old version of this rename utility is
sometimes called 'prename'. Newer versions may be called 'file-rename'.
NOTE: there is another renaming utility around called 'rename' but it is
NOT this perl rename tool and has completely different and incompatible
behaviour and command line options. can't remember the details right now
but you can check that you have the right rename installed if you get
output like this:
$ rename --version
/usr/bin/rename using File::Rename version 0.20
or check 'man rename' - if it mentions perl, it's good.
> Your specification is mostly clear but does contains some ambiguity,
> for example:
> - "brackets", are they () or [] or {} ?
> - what "sequence number" does the second photo have?
> - is the "sequence number" inside a pair of brackets?
>
> To avoid this game of questions, it would help if you provide actual
> examples of the various before and after filenames, so that anyone
> tempted to offer any solution can see and test exactly the names you
> have, and want.
agree with this too.
but in the meantime, try something like this to start with:
# DD MM YYYY (nnn)
rename -n 's/(\d\d)(\d\d)(\d{4})\./$3-$2-$1(000)./;
s/(\d\d)(\d\d)(\d{4})(\(\d{3}\))\./$3-$2-$1$4./;
' *.jpg
As the comment line tries to show, the first s/// statement matches and
replaces filenames WITHOUT the 3-digit sequence (and adds a sequence of
"(000)"). The second matches filenames WITH them.
This will replace both kinds of filenames іn one operation and neither
of them will return a replacement filename when they don't match.
Note the '-n' option. That's a dry-run option for testing...from the
rename man page:
-n, -nono No action: print names of files to be renamed, but don't
rename.
If a test run does what you want, run it without '-n'. Or with '-v' for
verbose output as it renames your files.
If it doesn't do what you want, play with the regexps until it does and
REMEMBER to check that you are using the '-n' option before hitting
enter.
Also, it's *always* a good idea to test with a copy of a small but
representative subset of your files in a different subdirectory before
doing something irreversible to the originals....if you mess up, it's no
big deal, just delete the mess and copy them again.
craig
--
craig sanders <[email protected]>
_______________________________________________
luv-main mailing list
[email protected]
https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main