Author Topic: Command Line to add Meta from filename  (Read 3222 times)

0 Members and 1 Guest are viewing this topic.

Antoine

  • Guest
Command Line to add Meta from filename
« 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.

RTT

  • Administrator
  • *****
  • Posts: 778
Re: Command Line to add Meta from filename
« Reply #1 on: August 01, 2011, 05:34:36 PM »
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

  • Guest
Re: Command Line to add Meta from filename
« Reply #2 on: August 01, 2011, 06:06:01 PM »
That is exactly what I needed, but cannot put my hands back on it !

RTT

  • Administrator
  • *****
  • Posts: 778
Re: Command Line to add Meta from filename
« Reply #3 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.

Antoine

  • Guest
Re: Command Line to add Meta from filename
« Reply #4 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 ;)