Author Topic: "If then"-syntax in BASH script with multiple expression keep failing  (Read 1876 times)

martenzi

  • Jr. Member
  • **
  • Posts: 15
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: "If then"-syntax in BASH script with multiple expression keep failing
« Reply #1 on: October 09, 2016, 08:37:13 AM »
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.
« Last Edit: October 12, 2016, 07:18:48 AM by Phil Harvey »
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

martenzi

  • Jr. Member
  • **
  • Posts: 15
Re: "If then"-syntax in BASH script with multiple expression keep failing
« Reply #2 on: October 11, 2016, 05:48:29 PM »
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?:
Code: [Select]
-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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: "If then"-syntax in BASH script with multiple expression keep failing
« Reply #3 on: October 12, 2016, 07:20:47 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).