The following script is a dynamic renamer that performs one or more transformations in arbitrary order. You don't have to modify the script to change the rename behavior - instead, you just specify the transformations you want performed in the DOpus Rename New name field. If you want to save the sequence, just save it to a new Preset and you can recall it again later. This helps you build a rename script live for use in the Rename dialog or in a button.
The transformation operations are listed below, and are specified as short flags. Each flag performs a simple transformation. Adding additional flags creates a chaining of transformations, allowing the building of complex renames very quickly and easily. Flags perform the transformations in order they are specified, so this allows maximum control over when a transformation should occur.
As you add each transformation flag to the New name field, the Preview window will show you how a flag affects the file name.
version: 1.12
Transformations
-
-c case;
follow with any of ulULtT (u=upper or l=lower first, U or L all, t=titlecase, or T=titlecase strict) -
-d date append/prepend;
format:-d/outspec/
or-d/inspec/outspec/
(-D prepends), *spec is a strftime template;
default outspec: -d: '%d-%m-%Y', -D: '%Y-%m-%d '; inspec is pulled from filename between %% and %% (use a transform to insert them first) -
-dd date guessing;
format:-dd
or-dd/outspec/
, *outspec uses printf formats in Date::Manip::date -
-e exclude files matching pattern;
format:-e/RE/
use -E to ignore suffix -
-f files or folders only: f=files-only, F=folders-only
-
-h html to ascii
-
-k kill text after (-k) or before (-K) specified string, inclusively (default) or exclusively:
-k/string/[ei]
-K=before optional: e=exclude, i=ignore case -
-r replace;
format:-r/oldstr/newstr/gie
optional: g=global, i=ignore case, e=evaluate newstr as perl code -
-rr replace range;
format:-rr/<range>/newstr/
, rr=front, RR=rear; replace range of chars with newstr, is either m or m-n and m <= n -
-R reverse;
format:-R/oldsep/newsep/
reverse words using oldsep string replaced w/newsep string; empty oldsep reverses characters; empty newsep uses oldsep -
-s suffix change,
format:-s[lun]
lowercase (default), uppercase, none -
-S sort;
format-S/oldsep/newsep/r
sort words using oldsep string replaced w/newsep string; empty oldsep reverses characters; empty newsep uses oldsep;
optional: r=reverse sort -
-t transliteration;
format:-t/srchlist/tolist/cds
optional: c=compliment srch list, d=delete found but unreplaced, s=squash dups -
-u uri unescape
-
-U Unicode to ASCII
-
-w whitespace spans to single space
-
-x trim characters;
format:-x[[=]n]
, x=front, X=rear; optional: n=number of chars (defaults to 1); '=' means leave n chars -
-z zero pad number;
format:-zn
, where n is final number of 0-padded digits -
-# number; increase #'s for padding or more digits;
flags[r^]
r=random, ^=numbers in front -
-/ regular expression substitution;
format:-/RE/replacement/gie
optional: g=global, i=ignore case, e=eval expression -
-^ append text at beginning;
format:-^/text/
-
-$ append text at end;
format:-$/text/
-
-+ add 1 (or n) to final numeric sequence;
format:-+n
optional n may be negative
Example
As an example, in the following transformation:
-u -h -s -b -a/El/ -cu -r/-/_/g -w
- -u flag replaces URI escapements (%20, etc.) with standard characters,
- -h replaces html entities,
- -s then lowercases the file suffix,
- -b then removes any bracketed content including the brackets,
- -a moves articles to the end including the user-defined "El" article,
- -cu uppercase the first word of the filename,
- -r replaces dashes with underbars globably (g flag), and
- -w finally cleans excessive whitespace.
I'll add more functions as people request them.
Setup
The script requires ActivePerl. Use version 5.20.2.2001 (not 5.18.4.1804). It is free, safe, easy, and non-invasive to install. Get the 32-bit or 64-bit installer as appropriate for your version of Windows:
ActivePerl 64-bit
ActivePerl 32-bit
Why did I use Perl? It is an exceptionally fast, rich, power scripting language that was designed to tasks such as this. Most transformations are a couple of lines of code - adding new functionality is very easy, so feel free to ask.
Note: Version 1.11 requires a module update in ActivePerl. After installing ActivePerl, open a Windows command shell, and enter the command:
ppm install date-manip
and hit Enter. When the update is complete, you can exit out of the command shell. If you already have the date-manip module installed, use:
ppm update date-manip
instead.
To install the Dynamic Renamer rename script, download the latest zip file below, unzip it, and then open Directory Opus' Rename dialog, and use its File > Import menu item, and select the Dynamic Renamer .orp file.
Comments welcome, assistance provided.
MrC
_Dynamic Renamer 1.12.zip (7.27 KB)
_Dynamic Renamer 1.11.zip (6.19 KB)