RTTSoftware Support Forum

PDF-ShellTools => General => Topic started by: Antoine on August 01, 2011, 01:35:44 PM

Title: Command Line to add Meta from filename
Post by: Antoine on August 01, 2011, 01:35:44 PM
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.
Title: Re: Command Line to add Meta from filename
Post by: RTT on August 01, 2011, 05:34:36 PM
You can do it with the command line interface, SetMetadata (http://www.rttsoftware.com/Manuals/STIndex.htm?pageURL=ST/English/InfoEdit.htm#cmdline) 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?
Title: Re: Command Line to add Meta from filename
Post by: Antoine on August 01, 2011, 06:06:01 PM
That is exactly what I needed, but cannot put my hands back on it !
Title: Re: Command Line to add Meta from filename
Post by: RTT on August 02, 2011, 01:09:25 AM
Quote
but cannot put my hands back on it !
Why not?!!
Here I leave some code to help you starting.
Code: [Select]
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 + '"');
    }
}

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.
Title: Re: Command Line to add Meta from filename
Post by: Antoine on August 02, 2011, 01:15:41 AM
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 ;)