I want to select image files based on the preservedfilename field being empty, or null.
I have tried:
exiftool -if "$preservedfilename=~/ /"
exiftool -if "$preservedfilename=~//"
exiftool -if "$preservedfilename=~/ /i"
exiftool -if "$preservedfilename=~//i"
These result in file that are known to have empty, or no, values in the preservedfilename field "failing" the condition. I can get the -if to work when there is something in the field, no problem. But when nothing has been entered yet is where I fall short.
What am I not understanding?
Also, once I get this figure out, I would like to be able to select files base on if preservedfilename does, or does not match filename.
Thanks in advance.
An example of a command I use a lot is this
exiftool -if "defined $Headline and $Headline=~ /(^\s*$)/" -Headline= <DIR>
This command, in this case, checks to see if there is a Headline tag (defined $Headline), and if it has either not characters in it, or is filled with just whitespaces (space, tabs, etc), and then removes the tag if this is the case.
You could use something like this
exiftool -if "defined $preservedfilename and $preservedfilename=~/(^\s*$)/" <DIR>
Quote from: Tarn on February 21, 2013, 05:32:43 PM
Also, once I get this figure out, I would like to be able to select files base on if preservedfilename does, or does not match filename.
To list files where PreservedFilename does not equal the filename
exiftool -if "$PreservedFilename ne $filename" -none <Dir>Replace
ne with
eq to get list where they do match.
I'm following Phil's example of using a non-existant tag (-none) to just list files. Of course, you can replace it with any tag you might want to actually find.
It sounds like you want something like this:
-if "not defined $preservedFileName or $preservedFileName eq ''"
If it can also contain spaces, then use $preservedFileName =~ /^\s*$/ as stargeek suggested instead of $preservedFileName eq '' in the above condition.
Or there is another technique if you just want to write PreservedFileName if it was empty:
exiftool -preservedfilename-= -preservedFileName="something" FILE
This technique works on a per-tag basis, while the -if condition is a go/no-go for the entire command.
- Phil
Quote from: StarGeek on February 21, 2013, 05:45:58 PM
You could use something like this
exiftool -if "defined $preservedfilename and $preservedfilename=~/(^\s*$)/" <DIR>
As you wrote it, it failed. After a little playing with it, I found that:
-if "$preservedfilename=~/(^\s*$)/" * does the trick!
Note: I use a single "*" to select the current working directory and any sub-directories below it. But
it only takes one level below.
Quote from: StarGeek on February 21, 2013, 05:53:17 PM
To list files where PreservedFilename does not equal the filename
exiftool -if "$PreservedFilename ne $filename" -none <Dir>
Replace ne with eq to get list where they do match.
This worked right off the shelf! And, as I knew I would be doing, I'm setting here shaking my head and going "Dummy!".
I'm guessing that using ">", "<", and "<>" don't work so well, huh?
I cannot thank you enough.
I have files from 2001 that I need to check. Some of my folders hold over 800 images (for just one shoot).
Needless to say you, Exiftool, and Phil have saved me countless mandays (possibly manweeks) with this feature alone.
Thank you, and Phil.
Quote from: Phil Harvey on February 21, 2013, 06:21:36 PM
If it can also contain spaces, then use $preservedFileName =~ /^\s*$/
The reason I was added the parentheses was because of the $/ to new line conversion. I didn't know about it at the time but the command wasn't working until I did that. I haven't checked if this behavior has changed or not.
Quote from: Tarn on February 21, 2013, 06:36:30 PM
Note: I use a single "*" to select the current working directory and any sub-directories below it. But
it only takes one level below.
Add
-r to recurse into all sub-directories.
Quote from: Tarn on February 21, 2013, 06:36:30 PM
This worked right off the shelf! And, as I knew I would be doing, I'm setting here shaking my head and going "Dummy!".
I'm guessing that using ">", "<", and "<>" don't work so well, huh?
I don't know. All the perl I know is from playing with Exiftool and getting it to do what I want. :D
Ah, found it. ">", "<", and "<>" are numeric operators, while "gt", "lt", "ne", and "eq" are string operators. I made that mistake at some point in the past, because once I googled Perl Operators, I recognized the page that came up.
First let me say thank you for an outstanding program. I cannot thank you enough.
Quote from: Phil Harvey on February 21, 2013, 06:21:36 PM
It sounds like you want something like this:
-if "not defined $preservedFileName or $preservedFileName eq ''"
I will try this as well.
Quote
If it can also contain spaces, then use $preservedFileName =~ /^\s*$/ as stargeek suggested instead of $preservedFileName eq '' in the above condition.
I'm not finding any empty fields that have just spaces (that I know ). But I will make a note of this and test it.
Quote
Or there is another technique if you just want to write PreservedFileName if it was empty:
exiftool -preservedfilename-= -preservedFileName="something" FILE
This technique works on a per-tag basis, while the -if condition is a go/no-go for the entire command.
-Phil
And yet another option. Thank you.
I have figured out how to take filename and put it into preservedfilename. I've even figured out how to
reconstruct the filename using the datetimeoriginal tag. And that is a godsend.
The problem I have is that what I was using to put the filename into preservedfilename tended to skip a file or two.
And going back through hundreds of images to find the one or two that got missed was a real pain.
This is good, very good.
Thank you.
Quote from: StarGeek on February 21, 2013, 06:45:38 PM
Quote from: Tarn on February 21, 2013, 06:36:30 PM
Note: I use a single "*" to select the current working directory and any sub-directories below it. But
it only takes one level below.
Add -r to recurse into all sub-directories.
I tried that. It's a good thing that I only work on copies of files; because, boy, did I mess things up pretty good.
My structure is: "T:\~Working\111009 - Clouds\Edited". And I may have several other sub-directories as well.
I sit in the ~Working directory. Any command I use works on all sub-directories if I use the *. To go further down
into "Edited" would change the preservedfilename I have in the edited files. And I use that to tell me what the
original file was.
Quote
Ah, found it. ">", "<", and "<>" are numeric operators, while "gt", "lt", "ne", and "eq" are string operators. I made that mistake at some point in the past, because once I googled Perl Operators, I recognized the page that came up.
Reminds me of a friend I had. He spoke his native English, French, German, and Spanish... fluently. He told me that remember the words was not his problem. It was remembering the sentence structure, nuances and such that gave him the problem. He'd speak in, say, Spanish, but sometimes use English sentence structure. Just like my using "<>" instead of "ne".
I've only had ExifTool since yesterday. And remembering the old DOS commands along with learning how to drive the new program is slowing me down a bit. But if I learn nothing else than what I know now, it will be enough.
Thank you for your help.
Quote from: StarGeek on February 21, 2013, 06:37:56 PM
The reason I was added the parentheses was because of the $/ to new line conversion.
Thanks, right. I keep forgetting about that. :P You can also avoid this problem by doubling the "$" symbol.
- Phil