Script method

Batch method Script The script method is probably the most advanced feature of Advanced Renamer. With this method a JavaScript experienced user can extend the program by writing custom methods right in the program. As with any method, the script method can be saved and opened by any other user on any other computer. Write the script in the text box and click Apply Script to see the result in the file list. The Pre Batch Script button can be used to setup prebatch variables.

How to use
The script in the method panel will get executed once for every file or folder in the list in the order the files are sorted in the list. The parameter index contains the number the item in the list has. The parameter item is an object representing an item in the list and contains every piece of information the program knows about this file or folder. The information can be used to create a new filename which will be set by returning the new filename. Remember the new filename must contain the extension of the file.

Objects specific to Advanced Renamer:
The app object has the following properties and methods:

app.currentIndex [readonly] The index of the currently processed item in the list.
app.currentItem [readonly] The currently processed item in the list.
app.exifToolValue(tag): string Returns the value of the specified tag from the ExifTool.
app.getItem(index) Returns the item at the specified index.
app.itemCount [readonly] The number of items in the list.
app.log(message) Writes a message to the log. To see the log messages, open the JS console through the button in the main toolbar.
app.logItem(item) Writes a message to the log containing the item.
app.parseTags(tags): string Parses the specified string for tags and returns the result.
app.prevItem [readonly] The previous item in the list.
app.readFileText(filename): string
New in version 4.16
Reads the entire text content of the specified file and returns it as a string.

If the file cannot be read, undefined is returned instead and a message is written to the log.

The return value of this function will be cached for better performance. The cache is cleared when the list is empties or a batch run is completed. Even though the result is cached, it is still recommended to avoid calling this function multiple times with the same filename in a single script execution. This can be avoided by reading the file in the Pre Batch Script.

Only files with approved file extensions can be read. To change the list of extensions in the Setting window.
app.readFileLines(filename): array
New in version 4.16
Reads the entire text content of the specified file and returns it as an array of strings, each representing a line in the file. Will use readFileText() to read the file content.

Important resources
JavaScript Reference
JavaScript Guide

Advanced Renamer uses an embedded light weight JS engine, so don't expect all the features of a full blown JS engine.