Can I use a directory and filename as a bool for an if statement?

Started by jens0771, December 16, 2021, 11:41:05 PM

Previous topic - Next topic

jens0771

Hey all, I was hoping I could get some feedback on a command I was attempting.

I'm dealing with Apple iPhone media, and sometimes there is an accompanying .AAE file to the .HEIC/.JPG/.MOV. Let's just take Apple's Live Photo's for instance. I'm able to get the HEIC & MOV files that make up the Live Photo move to a folder, lets say "Destination" by searching for specific tags that only reside in those two extensions that are a Live Photo pairing. Sometime there can be an accompanying AAE if there was an edit to the Life Photo. What I was working towards is to scan the "Source" folder for an AAE, if there are any, take the file name ie "IMG_1234" and see if that file name with an HEIC extension exists in the "Destination" folder, if so move the AAE file to the "Destination". Here is what I have so far:

exiftool -directory=desktop/Destination -r ~/desktop/Source -ext AAE -if '~/desktop/Destination/%f.HEIC'

So I'm doing the recursive search of the source, AAE extension only, and will move it to the destination folder only if there is an HEIC file with the same name already in the destination. I'm not sure first of all if providing a directory and filename will return a bool or not, probably not, and even if it did, I'm not sure I'm using the filename (%f) correctly to take the AAE filename and search for a HEIC equivalent.

If anyone has a better method, I'd love to hear it, otherwise please help me understand what I'm doing incorrectly.

Thanks in advance!

StarGeek

Quote from: jens0771 on December 16, 2021, 11:41:05 PM
exiftool -directory=desktop/Destination -r ~/desktop/Source -ext AAE -if '~/desktop/Destination/%f.HEIC'

The first problem is that the percent tokens such as %f have a limited scope and can't be used as if there were actual tags except in the case of the Filename and Directory pseudo-tags (see Writing "FileName" and "Directory" tags).

The second problem is that you can't use the -if option to check the existence of another file.  Exiftool will only operate on the file currently being processed.

What I think would need to be done is to use the -srcfile option.  There will be errors thrown for AAE files that don't exist, but they could be ignored.

exiftool -Directory=/target/Directory/ -srcfile /path/to/AeeFiles/%f.AEE /path/to/JpgFiles/

example using XMP
C:\>tree /f Y:\!temp\bbb
Folder PATH listing for volume DrivePool
Y:\!TEMP\BBB
├───SourceDir
│       File1.xmp
│       File3.xmp
│       
└───TargetDir
        File1.heic
        File2.jpg
        File3.mov

C:\>exiftool -directory=Y:\!temp\bbb\TargetDir -srcfile Y:\!temp\bbb\SourceDir/%f.xmp Y:\!temp\bbb\TargetDir
Error: Nothing to write - Y:\!temp\bbb\SourceDir/File2.xmp
    1 directories scanned
    2 image files updated
    1 files weren't updated due to errors

C:\Programs\My_Stuff>tree /f Y:\!temp\bbb
Folder PATH listing for volume DrivePool
Y:\!TEMP\BBB
├───SourceDir
└───TargetDir
        File1.heic
        File2.jpg
        File3.mov
        File1.xmp
        File3.xmp


An error is thrown for File2.jpg because there is no matching xmp file, but the other files are moved.

Adding --ext aae might be useful if there are already AAE files in the target directory.

See this thread for the source of this.

Side note, I had a real problem trying to test this out because it kept throwing Warning: New file name not allowed in Windows (contains ':').  I finally narrowed it down to \%f, so Windows is reading that as something else.  Had to change it to /%f for it to work.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

jens0771

Stargeek,

Thank you very much. This works just as I had imagined it. As you said, there will be error's saying the AAE file doesn't exist but that's perfectly fine by me, since I just want it to check to see if there is one, and if so move it.

You're a great help to this community, and I appreciate it.