Rename based on keyword found in PDF

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Rename based on keyword found in PDF

Postby Admin » Tue Nov 11, 2025 7:54 am

Add prefix to file name depending on what keyword is found in a PDF. eg. if Google then add Google, if Microsoft then add Microsoft, etc.
Have the keywords be user defined at the start of script.

Created with : https://bulkrename.software/js/

Code: Select all
// User-defined list of keywords to look for in each PDF
var keywords = ['Google', 'Microsoft', 'Apple', 'Amazon'];

// Default to keeping the original name
newName = name;

// Only examine PDF files
if (ext.toLowerCase() === 'pdf') {
    // Loop through each keyword and stop at first match
    for (var i = 0; i < keywords.length; i++) {
        var kw = keywords[i];
        // fileMatch returns the matching line or null if not found
        if (fileMatch(kw)) {
            // Prefix the filename (without extension) with the keyword and an underscore
            newName = kw + '_' + name;
            break;
        }
    }
}

// Examples:
// If name = "report.pdf" and the PDF contains "Google", then newName = "Google_report"
// If name = "summary.pdf" and no keywords are found, newName remains "summary"
Code: Select all
Admin
Site Admin
 
Posts: 3118
Joined: Tue Mar 08, 2005 8:39 pm

Return to Javascript Renaming


cron