Add day of picture creation as file prefix (check if already done)

Started by MarekV, May 28, 2018, 03:25:21 AM

Previous topic - Next topic

MarekV

Hi,

I have pictures organized in directory structure looking like this %Y\%Y-%m-%d <Comment>, while picture themselves mostly have camera original names. I copy the pictures to the structure from camera using Microsoft Windows "features" (they remove the Orientation from Exif and rotate the pictures accordingly while doing so) and subsequently adding the comment manually.

I wanted to add snapshots from iPhone to the same structure and achieved so by:
A. Installing iCloud Photos & Auto-synchronize
B. Installing Picasa and "Saving" all the synchronized photos
C. Using ExifTool to copy the files into the desired structure:
  exiftool.exe "-filename<FileModifyDate" "-filename<CreateDate"  -d "P:\%Y\%Y-%m-%d\%Y-%m-%d %%f.%%le" -ext jpg .

Now I want to use the extend the same naming convention for the already existing files, but I am on the way to generate really long commands while trying to detect whether the file already has the date prefix (without the detection the prefix gets duplicated). Moreover, the condition does not prevent the files with the date prefix to be excluded from the processing:
exiftool -if "not ( ${filename;s/^([0-9]{4})-([0-9]{2})-([0-9]{2}).*/$1-$2-$3/} eq ${datetimeoriginal;s/^([0-9]{4}):([0-9]{2}):([0-9]{2}).*/$1-$2-$3/})" -d "%Y-%m-%d %%f.%%le" "-testname<DateTimeOriginal" -ext jpg .

I would like to:
1. Keep YYYY-MM-DD prefix if it exists
2. Replace YYYYMMDD (or YYYY or YYYYMM) prefix (if exists) with YYYY-MM-DD
3. Add YYYY-MM-DD prefix if date prefix does not exist
4. Add comment from the last directory level without the "YYYY-MM-DD " prefix as the file comment
5. Improve the speed of the processing (we have about 5k photos in each year directory on local NAS and it takes about 30 minutes to process each year directory) with following command:
exiftool -if "$datetimeoriginal and $datetimeoriginal lt ${filemodifydate;s/[-+].*//}" "-dateTimeOriginal>FileModifyDate" -progress -overwrite_original -ext jpg -r .

Phil Harvey

Quote from: MarekV on May 28, 2018, 03:25:21 AM
the condition does not prevent the files with the date prefix to be excluded from the processing:
exiftool -if "not ( ${filename;s/^([0-9]{4})-([0-9]{2})-([0-9]{2}).*/$1-$2-$3/} eq ${datetimeoriginal;s/^([0-9]{4}):([0-9]{2}):([0-9]{2}).*/$1-$2-$3/})" -d "%Y-%m-%d %%f.%%le" "-testname<DateTimeOriginal" -ext jpg .

Your substitution expression for DateTimeOriginal in the -if condition won't work because DateTimeOriginal is formatted according to the -d option before your substitution.  Try this:

-if "${filename;s/^([0-9]{4})-([0-9]{2})-([0-9]{2}).*/$1:$2:$3/} ne ${datetimeoriginal#;s/ .*//}"


I would like to:
1. Keep YYYY-MM-DD prefix if it exists
2. Replace YYYYMMDD (or YYYY or YYYYMM) prefix (if exists) with YYYY-MM-DD
3. Add YYYY-MM-DD prefix if date prefix does not exist

Try this:

"-testname<${DateTimeOriginal}${filename;s/^\d{4,8}//}"

This will remove 4-8 digits if they exist at the start of the file name, then add the DateTimeOriginal in the format specified by the -d option.

Quote4. Add comment from the last directory level without the "YYYY-MM-DD " prefix as the file comment

"-comment<${directory;s(.*/)()}"

Quote5. Improve the speed of the processing (we have about 5k photos in each year directory on local NAS and it takes about 30 minutes to process each year directory) with following command:
exiftool -if "$datetimeoriginal and $datetimeoriginal lt ${filemodifydate;s/[-+].*//}" "-dateTimeOriginal>FileModifyDate" -progress -overwrite_original -ext jpg -r .

Is there a question here?  FYI, the -overwrite_original isn't doing anything here because you aren't modifying the file.

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