PDF-ShellTools > General

Command Line to add Meta from filename

(1/1)

Antoine:
Hello, I was wondering if we could batch add meta from filename using regex for instance.
My filenames are like " yyyymmdd Title of the doc.pdf " ...
Or maybe you know a tool that could do this.
There are multiple tools for tagging MP3s, but can't find any compatible with PDFs.

RTT:
You can do it with the command line interface, SetMetadata function, and any scripting language (DOS Batch, Windows Scripting Host, AutoHotKey, etc.) able to split the filename in the parts you want. Or I'm missing something?

Antoine:
That is exactly what I needed, but cannot put my hands back on it !

RTT:

--- Quote ---but cannot put my hands back on it !
--- End quote ---
Why not?!!
Here I leave some code to help you starting.

--- Code: ---var WshShell = new ActiveXObject("WScript.Shell")

function setMetadata(params) {
        //WScript.Echo( params );

        //64 bit Windows
        //WshShell.Run('"%ProgramFiles(x86)%\\PDF-ShellTools\\PDFShellTools.exe" SetMetadata ' + params, 1, true);

        //32 bit Windows
        WshShell.Run('"%ProgramFiles%\\PDF-ShellTools\\PDFShellTools.exe" SetMetadata '+params, 1, true);
    }

var fso = new ActiveXObject("Scripting.FileSystemObject");
//get folder object for current directory
var srcFolder = fso.GetFolder(".");
var files = new Enumerator(srcFolder.files);

// Loop through files
for (; !files.atEnd(); files.moveNext()) {
    var filename = files.item().Name;
    if (filename.split('.').pop().toLowerCase() == 'pdf') {

        //Filename=yyyymmdd Title of the doc.pdf
        var Title = filename.slice(9, filename.length - 4)

        setMetadata("\"Metadata='Title=" + Title + "'\" \"" + filename + '"');
    }
}

--- End code ---

Just save it with a .js extension, in the same folder where you have your PDFs, and change the metadata composition code according to your needs.

Antoine:
When I was saying I couldn't find it back, I was speaking of the SetMetadata function !
But thank you so much for the snippet code ;)

Navigation

[0] Message Index

Go to full version