Filename to Description
Latest update 12/20/2019, version 1.0.1
More than once I’ve encountered projects using image filenames as a means to convey caption text. This practice leads to some incredible long filenames. A recent project had filenames so long that once down a few subfolders, the path length exceeded the maximum my Windows server could handle. It was a mess to clean up, which became the reason to create this script.
Of course the proper way to store caption text is in the file’s metadata. A common practice is to store captions in the metadata field Description. That is what I’ve programmed this script to do.
- Copy filename to metadata description
- Option to remove number prefix
- Option to add closing period if absent
- Append to current description or replace
- Regular expression replacement
- Save and restore all settings
Instructions for use
The interface has four sections: Target folder, Options, Regex replace, and Settings. Enable desired options and click the OK button to begin. During processing, a progress bar is displayed. To cancel, press the ESC key. Otherwise, when complete, the number of images processed is reported. If any errors occur, a log file is written to the user desktop.
Section 1: Target folder
The folder of images to process. Click the button Folder… to select the desired location. If the option Include subfolders is checked, all folders within the selected folder are also processed. For each image discovered, the filename is examined, transformed as instructed, and the resulting text is inserted into the file metadata field Description. NOTE: filenames are not altered, only copied to the file’s metadata. Use other tools to shorten filenames if desired (see more below).
Section 2: Options
Remove number prefix — recognizes filenames that begin with numbers and optionally a single dot or lowercase letter. For example "15 the filename", "15.3 the filename", "18a the filename", "20.5b the filename". When such a pattern is detected, the prefix is removed. Prefixes typically serve to inform the designer of chapters or sections where images belong, information not ultimately preserved or used in captions. If intended to appear in captions, disable the option and number prefixes are included in the description text.
Append closing period if absent — the text copied to the description does not include the file extension, nor the separating dot (period) between it and the file name. Unless the filename has two dots (one acting as full stop, the next the name/extension separator), the text will lack a period. Enable this option to add one if missing.
Section 3: Regex replace
Also known as GREP. This section provides entry of up to three Find/Replace pairs, and for each, the switches g (greedy) and i (case-insensitive). The defined replacements are performed in the order shown on screen. Leave blank any (or all) not needed, otherwise enter a valid regular expression in one or all, along with a valid replacement expression for each. Filenames are tested against the expressions and transformed accordingly. For example, to remove parenthetical information (perhaps instructions to the designer, more information that doesn’t belong in a filename). In this example, the regular expression (.*)\([^)]*\)\W*(.*) finds and captures text near other text wrapped in parenthesis. The Replace expression $1$2 is the text captured less the parenthetical. The result is "(Put this in chapter one) Lake at sunset.tif" becomes "Lake at sunset" (the script already ignores the file extension). For only a parenthetical at the beginning of the filename, swap the first capture group for a start of line instruction: ^\([^)]*\)\W*(.*) and replacement $1 in that case. The range of possible replacements is extensive for users familiar with regular expressions.
Section 4: Settings
The current options may be saved and restored later. Select from the Load drop-down list to choose saved settings, which then updates the current options. Click the Delete button and the saved settings selected in the Load drop-down list are permanently removed. Click the Save button, provide a name for the settings, and the current options are preserved. If the name already exists, the user may choose to replace the saved settings.
The script provides default saved settings named [Default]. These settings cannot be deleted but may be updated to any desired values by saving settings and providing the name [Default], which then overwrites the default settings.
Each time processing begins, the current options are preserved, and the next time the script is launched, options are restored to the last values used.
This script is the first step toward resolving long filenames meant to convey photo captions. With the captions now preserved, the next step is to shorten the filenames. If the images are not yet placed in a layout, use a file renaming utility to truncate the filenames. A popular utility is A Better Finder Rename. However, if the images have been placed into a page layout, renaming the files by any means causes the links to become broken and time-consuming to resolve. Fortunately, if the layout application is InDesign, there is a solution. See the InDesign script Links Shorten Filenames. Also see the InDesign script Links Remove Number Prefix, which may be useful as well. After preserving the captions in the file metadata using this script, use the related InDesign scripts to shorten the filenames and update each link.
Filename to Description
License details included in download
For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.
IMPORTANT: by downloading the script you agree that the software is provided without any warranty, express or implied. USE AT YOUR OWN RISK. Always make backups of important data.
Version 1.0.1 (191220)
- Fix window button return value problem with Windows close button.
Version 1.0 (191124)
- Initial release.