Author Topic: Write folder name to metadata field  (Read 6825 times)

0 Members and 1 Guest are viewing this topic.

Markus

  • Guest
Write folder name to metadata field
« on: September 02, 2012, 04:51:44 PM »
I have a short question. Is it possible to write the folder name to a PDF metadata field?
I have a lot off PDFs in different folders and the folder name is a serial number related to the PDF contents. I want to write this number to the PDF, automatically.

The files are in "M:\Service\09 - Pictures\#109\109097", for example, and I want only to write the 109097 to a PDF metadata field.

Thanks


RTT

  • Administrator
  • *****
  • Posts: 918
Re: Write folder name to metadata field
« Reply #1 on: September 02, 2012, 05:41:20 PM »
Hello Markus,

With the newest version we have scripting capabilities in some of the tools, so yes it can be done easily.
We will use the Edit Info Fields batch tool.
Start it and enable the field to where you want to extract the folder name.
Now click the right pointing arrow, at the right of the field, and click the "Manage scripts" item. The help topic linked above don't reflect yet this new functionality, so take a look to the first attached screenshot to better understand what I'm talking about.

In the script editor that will show up create a new script and name it FolderName, and in the editor put this code
Code: [Select]
function FolderName() {
    var parts = BatchFile.Filename.split('\\');
    return parts[parts.length -2];
}
So it looks like the second attached screenshot.

You can now click the run, or "Test it", button to see if it is working. Click the OK button to exit, saving the changes.

Now in the Edit Info Fields batch tool field enter the name of the function, inside square brackets, so it looks like in the third attached screenshot. In this example I'm using the Title field as the field to where the folder name will be written. Any field can be used, and you may add more functions, field reference constants or plain text to compose the field content.
And you are ready to run it ;)

Let me know if the code needs any change, to deal with any special case you may have.