Batch rename

This tool is used to easily rename the documents files, using their document metadata fields as source to compose the new file name and/or folder name. Along with the possibility to use metadata contents there are also useful functions to add sequential numbering and dates, change letter case, search/replace, sub-string replace, string split, and for more complicated name schemes extra functionality provided by custom scripting.

Renamer tool screenshot

While the rename formula is being composed the tool shows, in the list of files to be renamed, how the new names look like, so we can easily check and change the formula accordingly to our needs.

The rename formula can contain any static text, and to quickly reference metadata fields, or apply any of the special functions, we can use the right pointing arrow button, at right of the rename formula field, to show,and choose, among the list of available options.

The metadata fields are referenced by a square bracket constant, such as [Title] or [Subject].

As with static text, and metadata field constants, the Counter and Date functions take effect at the insertion place, and show a specific configuration panel before added to the formula, as depicted in the above screenshot.

The modifying functions (letter case, replace, sub-string, split) work modifying the part of the formula affected by the function, so before entered the user should select the part of the already entered formula to affect.
Some examples:
- Upper case the current filename: [SetCase:U]([F])
- Title as new name, but replace the word "foo" with "bar": [ReplaceS:foo|bar]([Title])

The scripts sub-menu provides access to the scripting functionality of the tool, where script functions can be coded and used later the same way as the, explained above, metadata fields constants or modifying functions.

Manage Scripts Menu

The manage scripts item opens the same scripts manager and editor of the My Scripts tool, and the scripts that can be coded share the same specificities, except for the fact than in this case the script should have a main function whose return will be the text to be used in the place where its reference is entered in the rename formula. For this to work, the script name must also have exactly the same name of this function. For test proposes, running the script from the editor will show up a message box with the result of the function.
The access to the internal functionality is provided by two root objects, one named BatchFile, referent to the file being processed IFileObject, and a CurrentField named object that contains the file being processed current name, or the data passed as parameter, if the script function is used in modifying mode.

So, if we want to create a function to revert the text passed as parameter, we can create a script named Reverse, with this VBScript code:

Function Reverse
   Reverse=StrReverse(CurrentField.Value)
end Function

And use it in the rename formula, using the modifying mode, to invert, in this example, the subject field : [Reverse]([Subject])

One example of the usage of the BatchFile object can be, using JScript:

function CreationDatePlusOne() {
    if (BatchFile.Metadata.CreationDate !== undefined) {
        var dt = new Date(BatchFile.Metadata.CreationDate);
        dt.setDate(dt.getDate() + 1);
        return dt.toLocaleDateString()
    }
}

That returns the metadata creation date field plus one day, and can the be used in the rename formula this way: [Title]_[Subject]_[CreationDatePlusOne]

The tool can be used also to organize the files in a folder structure. The files can be renamed and moved to a new, or existing, folder using the rename formula to compose the new file, and location folder, name. To define that a specific part of the rename formula is related to a folder name, instead of the new file name, there is only the need to add the folder name separator, the backslash "\" character, to separate the parts that are folders names from the last part that is the new filename.The tool can construct a full, or relative, file path, e.g. "C:\PDFs\[Author]\[Title]\[F]", or "[Author]\[Title]\[F]".