Custom logic
Rename files with JavaScript logic
JavaScript rules are for cases where built-in rules are not expressive enough. They let you calculate a new name from file name, path, index, and supported file APIs.
Best for
Use this when renaming depends on if/else logic, file content, file size, index math, or a custom naming formula.
Rename examples
Use file content
note.txt
Project_Plan_note.txt
Add size label
photo.jpg
[MEDIUM]_5MB_photo.jpg
Custom extension logic
document.txt
document.zip
Common use cases
- Use the first line of a text file as part of the name.
- Add labels based on file size or custom conditions.
- Implement a naming formula that combines multiple built-in ideas.
How to use it
- 1Choose the JS script rule.
- 2Write a main function that returns the new file name.
- 3Test with preview and logs before applying to real files.
FAQ
When should I use JavaScript instead of regex?
Use regex for pattern replacement. Use JavaScript when the result depends on branching, calculations, or file APIs.
Should I test scripts before applying?
Yes. Preview and logs are important for custom scripts because code can affect each file differently.