Author Topic: Write parts from the filename to Metadata  (Read 16125 times)

0 Members and 1 Guest are viewing this topic.

Torschmied

  • Newbie
  • *
  • Posts: 28
Write parts from the filename to Metadata
« on: October 02, 2013, 01:19:46 PM »
Hello,

I have a question. We get now Service reports in PDF form from our Technicians. >From a new Software
The PDFE makes a copy off it for our server.
Is it possible to write some Information from the File name to the Meta data’s ?

Servicebericht%LB335000015%MA285065%PR242069%2013_09_30.pdf

That’s will save a lot of work if it's possible

Thanks for feed back




RTT

  • Administrator
  • *****
  • Posts: 907
Re: Write parts from the filename to Metadata
« Reply #1 on: October 02, 2013, 05:42:46 PM »
Quote
Is it possible to write some Information from the File name to the Meta data’s ?
Yes, you can use the scripting functionality of the Edit Info Fields batch tool. Read the last paragraph and check the sample scripts provided in the tool.

Or the My Scripts tool.

For the script, you can use a regular expression such as this to isolate the elements you want to extract.

Here is an example, to use in the Edit Info Fields, to extract the "Kommission" value.
Code: [Select]
function GetMA() {
    var regex = new RegExp("%MA(\\d{0,})", "g");
    var match = regex.exec(BatchFile.Filename);
    if (match !== null) {
        //pdfe.echo(match[1]);
        return match[1]
    } else {
        return ""
    }
}
After script created, you just need to refer its name in the field where you want to use it, e.g. in the Title field (see second attached screenshot).

Using the My Script batch tool, you can execute the operation, for all the fields, in just one script.

Let me know if you need further help.

Torschmied

  • Newbie
  • *
  • Posts: 28
Re: Write parts from the filename to Metadata
« Reply #2 on: October 02, 2013, 05:49:06 PM »
Hello

Thanks for the small script to write parts from the filename to the Metadatas, but I have a problem with it. It shows me two times the 285065 and also when I take it to the Metafield as your description it was not filled ? :-[

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Write parts from the filename to Metadata
« Reply #3 on: October 02, 2013, 06:10:27 PM »
Quote
It shows me two times the 285065
I suppose you are referring to when tested in the script editor. The first one is because I added a not needed "pdfe.echo(match[1]);" line, and the second time shows the return value of the function.
Quote
also when I take it to the Metafield as your description it was not filled
That's because of that above referred line "pdfe.echo(match[1]);" that really needs to be removed, as this batch tool doesn't provide output console, so it halts the script at that line. Sorry, my bad for not testing it before posting :-[
I've commented that erroneous line in the above script, for further reference.

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Write parts from the filename to Metadata
« Reply #4 on: October 03, 2013, 01:47:13 AM »
Here I leave a more advanced example, that covers the three parts you want to extract, that uses only one script. The part to extract is defined by a passed parameter.
Code: [Select]
function GetPartFromFilename() {
    var regex = new RegExp("%MA(\\d*)%PR(\\d*)%([0-9_]*)", "g");
    var match = regex.exec(BatchFile.Filename);
    if (match !== null) {
        switch (CurrentField.Value) {
        case 'MA':
            return match[1];
            break;
        case 'PR':
            return match[2];
            break;
        case 'Date':
            var d=match[3].split('_');       
            return d[2]+'.'+d[1]+'.'+d[0];
            break;
        }
    }
}
Call it as:
[GetPartFromFilename](MA) to get the "Kommission"
[GetPartFromFilename](PR) to get the "Auftragsnummer"
[GetPartFromFilename](Date) to get the "Datum"


Torschmied

  • Newbie
  • *
  • Posts: 28
Re: Write parts from the filename to Metadata
« Reply #5 on: October 11, 2013, 02:40:04 PM »
Perfect

many thanks

Torschmied

  • Newbie
  • *
  • Posts: 28
Re: Write parts from the filename to Metadata
« Reply #6 on: November 27, 2013, 08:28:26 AM »
Hello

sometimes I have a problem with this nice script.
sometimes it is not working correctly. somtimes I get Filename like Serviceberichte---.pdf ore berichte 286444-242111-2013_11_27.pdf

looks like a timing problem ore what you mean.
LG Markus


RTT

  • Administrator
  • *****
  • Posts: 907
Re: Write parts from the filename to Metadata
« Reply #7 on: November 27, 2013, 11:38:53 PM »
This script in not responsible of the filename, it only parses it. If indeed the files have these problematic names, then the problem must be in the system that gives these names to the files.  From your first post, these names are being served by some other software.

Torschmied

  • Newbie
  • *
  • Posts: 28
Re: Write parts from the filename to Metadata
« Reply #8 on: November 28, 2013, 10:43:24 AM »
Hi
Maybe my explonatition was not good enave
I make the following.
I get new Files from a software to a Networkdrive
PDFE make a Copy from it to External USB3 Harddisk ( all Pdf for the server )
the file name ist every time like this
Servicebericht%LBTEST%MA999999%PR999999%2013_11_12.pdf
in the automatic prozess from pdfe I write with the script the Metatags
after them I rename the file name with the rename option and call again the script

Servicebericht-[GetPartFromFilename](MA)-[GetPartFromFilename](PR)-[GetPartFromFilename](Date)

most time it works but not everytime ?
is it possibel that the Metagas not reddy write when the rename prozess start ?


RTT

  • Administrator
  • *****
  • Posts: 907
Re: Write parts from the filename to Metadata
« Reply #9 on: November 29, 2013, 12:48:32 AM »
From what I'm understanding, you have a PDFE task automation folder monitor, set up to the USB3 hard disk target folder, that runs two tasks. The first edits the files metadata and makes use of the above script to extract the related parts from the filename. The second task renames the files and also uses the same script to generate the new filename.

Not related for the problem, but why are you using the script in the rename task, if you already have the same filename parts saved to the metadata fields? In the rename expression you only need to refer to these custom fields, filled by the first metadata edit task. From the screenshot you attached, the data seems to be the same.

Anyway, does the problem only occurs in the generation of the new filename, or you are also getting empty, or trimmed, metadata fields from the edit metadata task?

Do you get to see this problem if you manually use the rename tool, from the batch tools, against the original files in the network drive? Just select a batch of these files and start the rename tool with the same rename expression. You don't need to run the tool. Just check if the problem shows in the tool new file names preview panel.

Quote
is it possibel that the Metagas not reddy write when the rename prozess start ?
The tasks are run in sequence and the next tasks uses the data precessed from the previous, so that should not be happening.

Torschmied

  • Newbie
  • *
  • Posts: 28
Re: Write parts from the filename to Metadata
« Reply #10 on: November 29, 2013, 10:43:23 AM »
HI

Ok I have changed the rename job and test it.
and also I take a look for the Metadatas.
Thanks

heine

  • Newbie
  • *
  • Posts: 2
Re: Write parts from the filename to Metadata
« Reply #11 on: December 26, 2013, 07:17:31 PM »
Hi,

I got a similar problem, but I wasn't able yet to adapt the script to my situation yet. I got thousends of PDF files named this way:

Author - Title.pdf

For example:
Mouffe, Chantal - The Return of the Political.pdf

Would it be possible to write parts of the name directly to the Metadata? I would like to write the first part of the filename (before the hyphen) to the Metadata field "author" and the second part of the filename (after the hyphen) to the field "title". Any hint would be a great help!

Best,

heine


RTT

  • Administrator
  • *****
  • Posts: 907
Re: Write parts from the filename to Metadata
« Reply #12 on: December 27, 2013, 12:11:14 AM »
In the title field type:

[Split: - |1]([F])

And in the author field:

[Split: - |0]([F])

Check the attached image for context.

You can check the batch rename tool for other built-in functions you can use.
I still need to integrate the functions editor, as in the batch rename, in the edit info fields batch tool. That's why there is no reference to these in this tool yet. But they are functional already.

heine

  • Newbie
  • *
  • Posts: 2
Re: Write parts from the filename to Metadata
« Reply #13 on: December 27, 2013, 12:18:02 PM »
Thank you, it's working and saved me A LOT of time!