Create keyword from the file name, all name till first underscore

Started by seraosr, November 22, 2012, 01:27:27 PM

Previous topic - Next topic

seraosr

Hello Exif Forum,
congratulations to the author of the tool. It's the best tools to edit metadata easily.

I'm a newby hear. I found and read some documentation but i'm not able yet to do it myself.

Question: Every day my workflow produces 50 pdf files, then these pdfs are converted to the right format with a tool called "Pitstop" then these pdfs are cataloged for a DAM tool called "Canto Cumulus." PDF files are created as follows "name_code.pdf."

The intention is, with EXIF, collect the file name to "_code.pdf" and write in the 'Keyword' field.

On the final, the command script is attached to the a action folder that do this transformation and move the files to other folder to automatically being catalogued.

Regards
Ricardo
Portugal

Phil Harvey

Hi Richardo,

You want to manpulate the file name and write to another tag.  This can be done with a user-defined tag and a command like this:

exiftool "-keywords+=myname" FILE

where FILE is one or more file and/or directory names.

For this to work, you need to create a user-defined "MyName" tag, which can be done with this config file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyName => {
            Require => 'FileName',
            # remove "_code.pdf" from end of FileName
            ValueConv => '$val =~ s/_code\.pdf//; $val',
        },
    },
);


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

seraosr

Hi Phil,
thank you for you reply.
I've files with filename like:

AEAGR3_20112889_TXT.PDF
AEAPRGRAM5_20112275_CP.PDF
EF789EP_20112125_TXTLR.PDF
GH7CAEP_20113477_TXT.PDF
IT7DP_20101838_AVAL.PDF

So, for the code you kindly generate, i think that you assume that the '_code.pdf' is a fixed tag, but there isn't, file names are very different.

Thanks a lot. Congratulations for your job.

Ricardo

Phil Harvey

Hi Richardo,

Then just use "\w+" instead of "code" to represent a string of one or more word characters.  Also, you should use /i to make the extension case-insensitive:

            ValueConv => '$val =~ s/_\w+\.pdf//i; $val',
- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

seraosr

Hi Phil,
thanks in advance for all your help.

From our compreension how Exif works, we have 2 files, one batch file with "exiftool "-keywords+=myname" C:\PDFS" and a config file with the code you sent "%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyName => {
            Require => 'FileName',
            # remove "_code.pdf" from end of FileName
         ValueConv => '$val =~ s/_\w+\.pdf//i; $val',
      },
    },
);"


We have both files in a folder on c:\ together with "exiftool.exe", but if we run the batch file, we get no result. Can you tell us what are we doing wrong?

Thanks again
Ricardo

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

seraosr

Hi Phil,

yes i did.

The problem was that i was executing cmd, EXE and CONFIG file from Desktop.
Now I have - "EXIF.cmd", "exiftool.exe" and ".ExifTool_config" on %homepath%. Destination Folder now is C:\PDFS.

I have sucess when execute CMD file but on PDF the keyword added is "Myname" - The name you gave to TAG.

Can you please help.

Thanks again.
Ricardo

Phil Harvey

Oops, you're right.  I wanted to copy the MyName tag, not add the string "myname".  The command should have been:

exiftool "-keywords+<myname" FILE

(the "+" adds to the existing keywords.  Remove it if you don't want to preserve keywords that already exist in the file.)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

seraosr

:) :)

Phil, I understood all you wrote about the + and =.

in spite of it's working, the keyword added is the file name filename.PDF. To remove (.PDF) from Keyword can i remove .PDF from ValueConv => '$val =~ s/_code\.pdf//; $val',

I can only test again in Monday. Have a good weekend and thank you for all your work.

Regards
Ricardo

Phil Harvey

Hi Ricardo,

The problem is that you forgot the "/i" in the expression to make it case insensitive (your files are .PDF, and the expression has "\.pdf"):

         ValueConv => '$val =~ s/_\w+\.pdf//i; $val',

- Phil

Edit: Oops, sorry about getting your name wrong.  Fixed now.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

seraosr

Hi Phil,
i've tested you wrote and it's working,yupi! I want to thank you.

My problem is with my real PDF's files generated by a system from 'Kodak', exif is not accessing the files,.. Maybe some protection that i will try to find out.

Im mean while, thank you again.

Regards
Ricardo

seraosr

Hi Phil
apologizes for pushing this issue.

Our PDFS are protected after going to "pitstop" tool, I really need to write to the "Keywords" field in PDF.
I've changed the command line to:exiftool "-Xmp:subject+<myname" C:\EXIF\PDFS

Opening the PDF in Adobe Reader, the "keyword" is written in the keyword field, but with semicolons, ie: (; filename), i've attached an example. Can you please correct me!

Regards and thanks

Phil Harvey

The Adobe Reader screen shot doesn't help me.  An ExifTool output would be more useful.  But it could be there is a blank item in the XMP:Subject list.  If so, it was there before you added your "myname" item.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

seraosr

Hi, Phil
Attached the file (CCH-SEITA_20114530_CP_72dpi.txt) from ExifToolGUi. It's strange, no mencion to (;) symbol.

Can you help now, on to "Create keyword from the same Keyword" ??

Attached, the export file (CESPI-REC_20000000_TXT.txt) from a PDF File with a written Keyword.

It's possible to read that keyword and write on same field?

---- XMP ----
XMP Toolkit                     : Adobe XMP Core 5.2-c001 63.139439, 2010/09/27-13:37:26
Modify Date                     : 2012:12:04 17:06:10Z
Create Date                     : 2008:03:14 17:50:53
Metadata Date                   : 2012:12:04 17:06:10Z
Document ID                     : uuid:dd2f8b4e-9198-4172-9519-19fb92544a11
Instance ID                     : uuid:2e9074d2-e7ae-f74c-8cb3-56d6cd0b8970
Format                          : application/pdf
Creator                         :
Subject                         : NEW ARCHIVE: CESPI-REC_20000000_TXT.pdf
Producer                        : Creo Normalizer JTP
Keywords                        : NEW ARCHIVE: CESPI-REC_20000000_TXT.pdf

On field XMP: Subject, wanto to read and write only NEW ARCHIVE: CESPI-REC. Can you please help.

In previous, to Create keyword from the file name, all name till first underscore, we had:

.ExifTool_Config

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        Myname => {
               Require => 'FileName',
   ValueConv => '$val =~ s/_\w+\.pdf//i; $val',
        },
    },
);

Batch File

"exiftool "-keywords<myname" C:\EXIF\PDFS" and later "exiftool "-Xmp:subject+<myname" C:\EXIF\PDFS"

Have to Keep the tag  ValueConv ?

if you kindly help, i appreciated.

Regards
Thanks

Ricardo

Phil Harvey

Modifying the keywords or subject is a bit different because these are list-type tags.

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        Myname2 => {
               Require => 'Keywords',
               ValueConv => q{
                   $val = $val[0] if ref $val eq 'ARRAY';
                   $val =~ s/_\w+\.pdf//i;
                   return $val;
               },
        },
    },
);


With this, you can use this command to remove the end part of the file name from the keywords:

exiftool "-keywords<keywords" FILE

I don't see where the semicolon came from the file with the "CCH-SEITA" keywords. To make sure you don't have unwanted keywords, you could replace existing keywords with "<" instead of adding to them with "+<".

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).