Skip to main content

Pascal Script: Overview

TODO: Review if anything is missing from the original article.

The Pascal Script rule in ReNamer allows advanced users to create custom renaming logic using a scripting language based on Pascal/Delphi syntax. This provides full programmatic control over filenames, paths, metadata, and file system operations, making it ideal for complex tasks that standard rules cannot handle easily.

A collection of specialized functions and extensions makes scripting particularly powerful for Unicode filename handling, dynamic meta tag extraction, file system interactions, and integrating external data or tools.

Key concepts

  • Script Execution: Scripts are executed during the Preview stage just like other renaming rules, allowing you to manipulate the new name for every processed file.
  • Main Variable: The core of most scripts is the FileName variable of type WideString, which represents the new basename with extension. Modify this variable to change the new name for a file.
  • Path Access: The FilePath constant provides the full original path to the file, allowing direct file system operations, like reading content, applying external tools, etc.
  • Unicode Support: ReNamer's implementation uses WideString as the primary string type for full Unicode compatibility, supporting non-English characters and international scripts.

Extensions and functions

ReNamer extends the standard Pascal Script engine with custom types and functions tailored for renaming tasks, including:

  • Wide-string variants of common functions, e.g. WideUpperCase, WideReplaceStr.
  • File utilities, e.g. WideFileExists, FileReadTextLines.
  • Meta tag extraction via CalculateMetaTag.
  • Support for user-defined functions (UDFs) and importing external functions from DLLs.
  • Include directive {$INCLUDE 'filename.inc'} for reusing code from external files (available since v6.5.0.1 Beta).

Best practices

Follow these recommendations for reliable, efficient scripts:

  • Always prefer WideString over String for paths and names to ensure Unicode compatibility.
  • Avoid overriding built-in variables, types, or functions.
  • Some functions can modify the file system (e.g. create folders, delete files), use these with caution.
  • Test scripts thoroughly in Preview mode.

Warnings:

Warnings
  • Scripts execute on every preview, which can impact performance with large file lists or heavy operations.
  • Infinite loops or errors can freeze ReNamer, include safeguards like counters where needed.
  • File system changes in scripts are immediate and irreversible.

Further reading

These articles will help you learn and master the power of Pascal Script:

  • Basics – Syntax fundamentals, control structures, and quick start guide.
  • Types – Data types and structures.
  • Functions – Full reference of built-in functions.
  • Examples – Educational snippets and how-tos.
  • Library – Curated, ready-to-use scripts for common tasks and integrations with 3rd party tools.

You can also find examples, discussions and user contributed scripts on the User Forum.