"If then"-syntax in BASH script with multiple expression keep failing

Started by martenzi, October 09, 2016, 08:10:37 AM

Previous topic - Next topic

martenzi

Hi, Im a beginner to EXIFtool, Perl + BASH but I have programming experience in Python among other.

My goal is to sort a large collection of media files into Directories based on their available date tags. The collection is JPEGs and RAWS with various available date tags due to many years, many different cameras etc. The date tags are very arbitrary and thus messy, which is why Im trying to create date-order filter.
I know that I can use the -Directory tag to apply an order but that excludes the sorting in specific folders based on the available date tags.

If the file has DateTimeOriginal --> DateTimeOriginal/%Y-%m-%d/Filename
If the file has CreateDate --> CreateDate/%Y-%m-%d/Filename
If the file has DateTime --> DateTime/%Y-%m-%d/Filename
If the file has FileModifyDate --> FileModifyDate/%Y-%m-%d/Filename
(enough, you get the idea)

I do not fully understand how to create ARGFILE, I have created BASH scripts for other purposes. The syntax for IF statements and syntax for ARGILE is to me very unclear in the documentation, Im afraid.
I tried putting it all in in one long line with -execute but this too failed.
I really want to learn the conditional expressions as I intend too do a lot more conditional sorting besides date tags.

I appreciate any help.


#!/bin/bash
exiftool -v5 -r -if "($datetimeoriginal)" \
   '-Directory<datetimeoriginal' -d "DTO/%Y-%m-%d"
        $1
        -execute
-if "($FileModifyDate)" \
   '-Directory<FileModifyDate' -d "FileModifyDate/%Y-%m-%d"
        $1
-execute
-if "($createdate)" \
   '-Directory<CreateDate' -d "CreateDate/%Y-%m-%d"
        $1
       -execute
[\tt]



  • I have tried all possible combinations of these "if" expressions and can't get my hierarchical order to work.

  • I have looked at PERL syntax for "if else" and "if elif"


  • Im using Sublime Text 3 with what I think is BASH syntax. I tried to locate Perl syntax checker without success.

Phil Harvey

You can do this with a single exiftool command:

exiftool -v5 -r -d "%Y-%m-%d" '-Directory<FileModifyDate/$FileModifyDate' '-Directory<CreateDate/$CreateDate' '-Directory<DTO/$datetimeoriginal' DIR

No -if needed.

Note that I put FileModifyDate first because it always exists.  It will be overridden by the other assignments that come afterward if those tags exist.

- Phil

Edit: Added missing "/" in command.
...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 ($).

martenzi

Since I wanna have full oversight to which files that needs cleaning up, I´m organising the files based on the specific EXIF date tag that was used to create -Directory.
I can see how you think with your example but will this work to include full destination path for each tag?:
-Directory<EXIF selected DateTag based on Availability in File_%%e/%Y-%m-%d

If they simple go into date folders I loose track on which date tag that was available. I will have to clean up a bunch of files but its gonna be a lot more work if I have to make a second trial for each date folder.
Also - I noticed that EXIFtool can sometimes skip files despite having DTO and telling me that the folder was scanned but 0 images were read. I then have to go into the folder and check the extension and add this to the script. This seems to be an issue with older files but its not yet clear to me whats causing it. My workaround is to specify the extension.

Phil Harvey

I think I understood, and my command should do what you want, except now you have added %%e to the directory name, so you will have to add that to the command.

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