csv file for directory with pdf docx and odt files

Started by sevy, April 02, 2023, 11:59:39 AM

Previous topic - Next topic

sevy

Hello,

I'm trying to generate a csv file for files (pdf odt and docx) containing a specific keyword.
It's ok for pdf and docx files but if I had odt files... nothing is working.
It's quite weird because if I do it only for odt files, it's working.

Here are the command :

exiftool.exe -r -ext pdf -ext docx -if "qq($keywords $subject)=~/keyword/i" -FileName -subject -keywords -filetype C:\directory\ > file.csv
 is working
exiftool.exe -r -ext odt -if "$keyword=~/keyword/i" -FileName -keyword -filetype C:\Directory\ > file.csv
 is working
exiftool.exe -r -ext odt -ext pdf -docx -if "$subject=~/keyword/i | $keywords=~/keyword/i | $keyword=~/keyword/i" -FileName -filetype C:\directory\ > file.csv
 is not working
exiftool.exe -r -ext odt -ext pdf -ext docx -if "qq($subject $keywords $keyword)=~/keyword/i" -FileName -filetype C:\directory\ > file.csv
is not working

Does anyone have an idea of what's happening ?

ExifTool version : 12.59

thanks in advance

StarGeek

What exactly do you mean by doesn't work?  In what way doesn't it work?  What is the expected output?

I suspect that this is a FAQ #3.  A quick check of the odt files I have (only 98 of them) shows that none of them have a Subject, Keywords, or Keyword tag.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sevy

#2
I have not result, the csv file is empty if the operation is done on pdf docx and odt files.
But, if I run ET only on pdf and docx files, it's good, files matching the "keywords term" are selected.
If I run ET only on odt files, it's also good, the matching files are in the csv files.
but, in this scenario, I got 2 csv files.

For pdf files, I search the "keyword term" on keywords or subject tags. "Keywords term" for docx files are stored in keywords tags.
But for odt files, they are stored in "keyword tag" (with no S at the end) (according -G4).
It's the reason why I tried
"qq($subject $keywords $keyword)=~/keyword/i"
with no result.

StarGeek

If a tag does not exist in a file, then that part is automatically false.  So if any of the tags in the qq operation don't exist, then that will fail.  Note that under Windows in versions before version 12.41, there was a long standing bug where an non-existent tag would have a default value of false/0. This is a mistake I still keep making and have to think carefully about.

The pipe character | is a bitwise or.  You want to use the logical or, which is simply or

Try this.
-if "($subject and $subject=~/keyword/i) or ($keywords and $keywords=~/keyword/i) or ($keyword and $keyword=~/keyword/i)"

Example output
C:\>exiftool -G1 -a -s -Subject -Keywords y:\!temp\Test4.jpg
[IPTC]          Keywords                        : Keyword1

C:\>exiftool -G1 -a -s -if "($subject and $subject=~/keyword/i) or ($keywords and $keywords=~/keyword/i) or ($keyword and $keyword=~/keyword/i)" -Subject -Keywords -Keyword y:\!temp\Test4.jpg
[IPTC]          Keywords                        : Keyword1
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

#4
Quote from: StarGeek on April 02, 2023, 02:49:01 PMunder Windows in versions before version 12.41, there was a long standing bug where an non-existent tag would have a default value of false/0.

Add the -m option if you want this behaviour with newer versions.

- Phil

Edit:  Oh.  This works for -p, but not -if.  Let me think about this.

Edit2: I could make this the behaviour for -if as well.  I wonder how much this would break people's existing commands?
...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 ($).

StarGeek

Quote from: Phil Harvey on April 02, 2023, 02:59:47 PMAdd the -m option if you want this behaviour with newer versions.

Ah, yes. I can see how that works.

Relevant line from the -m (-ignoreMinorErrors) option docs
    Note that this causes missing values in -tagsFromFile, -p and -if strings to be set to an empty string rather than an undefined value.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Quote from: StarGeek on April 02, 2023, 04:17:03 PMNote that this causes missing values in -tagsFromFile, -p and -if strings to be set to an empty string rather than an undefined value.

Thanks for pointing this out.  Since I've already documented this I will go ahead and fix it in version 12.60.

- 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 ($).

sevy

Thanks a lot for the explanation. I fear to become crazy because I thought it was working before... but now, I understand, it was before version 12.41 :-) Thanks StarGeek :-)
I run the new script on a test folder and it's working fine. It's currently working on the "production folder".