Rename images to "YYYY-MM-DD_Event-Name" from folder name

Started by lucky-guenni, February 16, 2022, 04:26:44 AM

Previous topic - Next topic

lucky-guenni

Hello,

I want to rename my photos and I'm an absolutely newbie with exiftool and also with regex

My system is a Windows 10 and exiftool 10.6.1.0 with the following folder structure:

x:\photo\YYYY\YYYY-MM\YYYY-MM-DD_Event-Name

here is my command, which I get out of the forum

exiftool -"filename<${DateTimeOriginal}_${directory;s/.+\///}_${Make}_${Model}.jpg" -d %Y-%m-%d_%H-%M-%S_%%-c -r -ext jpg x:\photo\YYYY

Result:
filename                        : YYYY-MM-DD_YYYY-MM-DD_Event-Name

what I like to have, but get no result, which work for me

if DateTimeOriginal is available in the file then rename the file to YYYY-MM-DD_Event-Name (DateTimeOriginal_Folder-Name-11-to-end)
Result:
filename                        : YYYY-MM-DD_Event-Name

if NOT DateTimeOriginal then rename the file to FolderName_No (YYYY-MM-DD_Event-Name_001) and set the -alldate to the date in the folder name
Result:

filename                        : YYYY-MM-DD_Event-Name_No
File Modification Date/Time     : 2016:09:04 06:22:20+02:00
Modify Date                     : 2016:09:04 06:22:20
Date/Time Original              : 2016:09:04 06:22:20
Create Date                     : 2016:09:04 06:22:20


I hope that it is understandable, what I want to have.
I know, that it could be possible that this could not be done in a one liner

Guenter

StarGeek

The easiest way to rename a file to the name of the directory it is in would be this, as long as you gave it a full path or were in the parent directory, i.e. you can't CD to the directory and use *.jpg.
exiftool -Filename=%-1:D%-c.%e /path/to/files/

But since you want other options, it'll be more complex.  It will have to be two commands since you want to either rename or rename and add data.  The "11-to-end" part needs some clarification though, as I don't know what you mean by that.

First command would be to add an -if option to the above command
exiftool -if "$DateTimeOriginal" -Filename=%-1:D%-c.%e /path/to/files/

Then for the files that don't include DateTimeOriginal
exiftool -if "not $DateTimeOriginal" -Filename=%-1:D%-c.%e "-AllDates<${Directory;m/(\d{4}-\d\d-\d\d)/;$_=$1} 00:00:00" /path/to/files/

Example output
C:\>exiftool -G1 -a -s -r -DateTimeOriginal Y:\!temp\aaaa
======== Y:/!temp/aaaa/2022-01-01_Wedding/Test1.jpg
[ExifIFD]       DateTimeOriginal                : 2022:01:01 12:00:00
======== Y:/!temp/aaaa/2022-02-02_Concert/Test2.jpg
    3 directories scanned
    2 image files read

C:\>exiftool -r -if "$DateTimeOriginal" -Filename=%-1:D%-c.%e Y:\!temp\aaaa
    3 directories scanned
    1 files failed condition
    1 image files updated

C:\>exiftool -P -overwrite_original -r -if "not $DateTimeOriginal" -Filename=%-1:D%-c.%e "-DateTimeOriginal<${Directory;m/(\d{4}-\d\d-\d\d)/;$_=$1} 00:00:00" Y:\!temp\aaaa
    3 directories scanned
    1 files failed condition
    1 image files updated

C:\>exiftool -G1 -a -s -r -DateTimeOriginal Y:\!temp\aaaa
======== Y:/!temp/aaaa/2022-01-01_Wedding/2022-01-01_Wedding.jpg
[ExifIFD]       DateTimeOriginal                : 2022:01:01 12:00:00
======== Y:/!temp/aaaa/2022-02-02_Concert/2022-02-02_Concert.jpg
[ExifIFD]       DateTimeOriginal                : 2022:02:02 00:00:00
    3 directories scanned
    2 image files read
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lucky-guenni

@StarGeek
thank you for your answer, will test this tomorrow, because I have to leave now
for the 1st quick view it looks very near to what I expect  :)

"11-to-end" means folder name from character 11 to the end e.g. 2022-02-16_Event-birthday --> Event-birthday

lucky-guenni

first: correct my counting:
"11-to-end" means folder name from character 11 to the end e.g. 2022-02-16_Event-birthday --> _Event-birthday

before doing anything
exiftool.exe -time:all -system:all -G -a -s "F:\Photo\1999\1980-12-21_birth-girlfriend-scan"
======== F:/Photo/1999/1980-12-21_birth-girlfriend-scan/exif-before-rename.jpg
[File]          FileModifyDate                  : 2021:06:05 19:37:04+02:00
[File]          FileAccessDate                  : 2022:02:17 06:08:13+01:00
[File]          FileCreateDate                  : 2022:02:17 06:03:36+01:00
[EXIF]          ModifyDate                      : 2021:06:05 18:37:04
[EXIF]          DateTimeOriginal                : 2021:06:05 18:37:04
[EXIF]          CreateDate                      : 2021:06:05 18:37:04
[EXIF]          OffsetTime                      : +02:00
[EXIF]          OffsetTimeOriginal              : +02:00
[EXIF]          OffsetTimeDigitized             : +02:00
[EXIF]          SubSecTimeOriginal              : 995
[EXIF]          SubSecTimeDigitized             : 995
[Composite]     SubSecCreateDate                : 2021:06:05 18:37:04.995+02:00
[Composite]     SubSecDateTimeOriginal          : 2021:06:05 18:37:04.995+02:00
[Composite]     SubSecModifyDate                : 2021:06:05 18:37:04+02:00
[File]          FileName                        : exif-before-rename.jpg
[File]          Directory                       : F:/Photo/1999/1980-12-21_birth-girlfriend-scan
[File]          FileSize                        : 2.2 MB
[File]          FileModifyDate                  : 2021:06:05 19:37:04+02:00
[File]          FileAccessDate                  : 2022:02:17 06:08:13+01:00
[File]          FileCreateDate                  : 2022:02:17 06:03:36+01:00
[File]          FilePermissions                 : rw-rw-rw-
======== F:/Photo/1999/1980-12-21_birth-girlfriend-scan/noexif-before-rename.JPG
[File]          FileModifyDate                  : 1998:07:31 09:21:30+02:00
[File]          FileAccessDate                  : 2022:02:17 06:09:05+01:00
[File]          FileCreateDate                  : 2022:02:17 06:08:49+01:00
[File]          FileName                        : noexif-before-rename.JPG
[File]          Directory                       : F:/Photo/1999/1980-12-21_birth-girlfriend-scan
[File]          FileSize                        : 6.5 kB
[File]          FileModifyDate                  : 1998:07:31 09:21:30+02:00
[File]          FileAccessDate                  : 2022:02:17 06:09:05+01:00
[File]          FileCreateDate                  : 2022:02:17 06:08:49+01:00
[File]          FilePermissions                 : rw-rw-rw-
    1 directories scanned
    2 image files read


tests

exiftool.exe -testname=%-1:D%-c.%e F:\Photo\1999\1980-12-21_birth-girlfriend-scan
'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/exif-before-rename.jpg' --> 'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan.jpg'
'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/noexif-before-rename.JPG' --> 'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan.JPG'
    1 directories scanned
    0 image files updated
    2 image files unchanged

   

exiftool -if "$DateTimeOriginal" -testname=%-1:D%-c.%e F:\Photo\1999\1980-12-21_birth-girlfriend-scan
'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/exif-before-rename.jpg' --> 'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan.jpg'
    1 directories scanned
    1 files failed condition
    0 image files updated
    1 image files unchanged


exiftool -if "not $DateTimeOriginal" -testname=%-1:D%-c.%e "-AllDates<${Directory;m/(\d{4}-\d\d-\d\d)/;$_=$1} 00:00:00" F:\Photo\1999\1980-12-21_birth-girlfriend-scan
'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/noexif-before-rename.JPG_exiftool_tmp' --> 'F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan.JPG'
    1 directories scanned
    1 files failed condition
    1 image files updated

   
real

exiftool -if "not $DateTimeOriginal" -Filename=%-1:D%-c.%e "-AllDates<${Directory;m/(\d{4}-\d\d-\d\d)/;$_=$1} 00:00:00" F:\Photo\1999\1980-12-21_birth-girlfriend-scan
    1 directories scanned
    1 files failed condition
    1 image files created


exiftool -if "$DateTimeOriginal" -filename=%-1:D%-c.%e F:\Photo\1999\1980-12-21_birth-girlfriend-scan
    1 directories scanned
    1 files failed condition
    1 image files updated

            
after the rename   

exiftool.exe -time:all -system:all -G -a -s "F:\Photo\1999\1980-12-21_birth-girlfriend-scan"
======== F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan-1.JPG
[File]          FileModifyDate                  : 2022:02:17 06:13:39+01:00
[File]          FileAccessDate                  : 2022:02:17 06:16:30+01:00
[File]          FileCreateDate                  : 2022:02:17 06:08:49+01:00
[EXIF]          ModifyDate                      : 1980:12:21 00:00:00
[EXIF]          DateTimeOriginal                : 1980:12:21 00:00:00
[EXIF]          CreateDate                      : 1980:12:21 00:00:00
[File]          FileName                        : 1980-12-21_birth-girlfriend-scan-1.JPG
[File]          Directory                       : F:/Photo/1999/1980-12-21_birth-girlfriend-scan
[File]          FileSize                        : 6.8 kB
[File]          FileModifyDate                  : 2022:02:17 06:13:39+01:00
[File]          FileAccessDate                  : 2022:02:17 06:16:30+01:00
[File]          FileCreateDate                  : 2022:02:17 06:08:49+01:00
[File]          FilePermissions                 : rw-rw-rw-
======== F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan.jpg
[File]          FileModifyDate                  : 2021:06:05 19:37:04+02:00
[File]          FileAccessDate                  : 2022:02:17 06:16:30+01:00
[File]          FileCreateDate                  : 2022:02:17 06:03:36+01:00
[EXIF]          ModifyDate                      : 2021:06:05 18:37:04
[EXIF]          DateTimeOriginal                : 2021:06:05 18:37:04
[EXIF]          CreateDate                      : 2021:06:05 18:37:04
[EXIF]          OffsetTime                      : +02:00
[EXIF]          OffsetTimeOriginal              : +02:00
[EXIF]          OffsetTimeDigitized             : +02:00
[EXIF]          SubSecTimeOriginal              : 995
[EXIF]          SubSecTimeDigitized             : 995
[Composite]     SubSecCreateDate                : 2021:06:05 18:37:04.995+02:00
[Composite]     SubSecDateTimeOriginal          : 2021:06:05 18:37:04.995+02:00
[Composite]     SubSecModifyDate                : 2021:06:05 18:37:04+02:00
[File]          FileName                        : 1980-12-21_birth-girlfriend-scan.jpg
[File]          Directory                       : F:/Photo/1999/1980-12-21_birth-girlfriend-scan
[File]          FileSize                        : 2.2 MB
[File]          FileModifyDate                  : 2021:06:05 19:37:04+02:00
[File]          FileAccessDate                  : 2022:02:17 06:16:30+01:00
[File]          FileCreateDate                  : 2022:02:17 06:03:36+01:00
[File]          FilePermissions                 : rw-rw-rw-
    1 directories scanned
    2 image files read


my expected result:

======== F:/Photo/1999/1980-12-21_birth-girlfriend-scan/1980-12-21_birth-girlfriend-scan-1.JPG
[EXIF]          ModifyDate                      : 1980:12:21 00:00:00
[EXIF]          DateTimeOriginal                : 1980:12:21[/b] 00:00:00
[EXIF]          CreateDate                      : 1980:12:21 00:00:00
[File]          FileName                        : 1980-12-21_birth-girlfriend-scan-1.JPG
[File]          FileSize                        : 6.8 kB

:)

======== F:/Photo/1999/1980-12-21_birth-girlfriend-scan/2021-06-05_birth-girlfriend-scan.jpg
[EXIF]          ModifyDate                      : 2021:06:05 18:37:04
[EXIF]          DateTimeOriginal                : 2021:06:05 18:37:04
[EXIF]          CreateDate                      : 2021:06:05 18:37:04
[File]          FileName                        : 2021-06-05_birth-girlfriend-scan.jpg
[File]          FileSize                        : 2.2 MB

:-\

$DateTimeOriginal11-to-end.jpg
YYYY-MM-DD_birth-girlfriend-scan.jpg

hope now is clear, what I want to achieve

Greetings from Germany

chuck lee

English is not my mother tongue. So, I am confused with your expected result. According to your first post.  File with datetimeoriginal is no problem.  File without datetimeoriginal will have an addition copy number.  I guess that is a typo in your expected result.

Do you mean that if a file without datetimeoriginal, you want to set the filename according to the modifydate of the file with datetimeoriginal?