Combine Rename and Move by File Extension

Started by lundjohnson, February 12, 2024, 01:20:22 AM

Previous topic - Next topic

lundjohnson

Currently I have 4 invocations of exiftool, which works fine.  Can I simplify/clean this up? Is there a better way to do it? I'm new to exiftool.
# Rename & Move Files by extension

# Set up test files
export MEDIA_TEST=/Users/bsj/Desktop/TestSet
export MEDIA_SOURCE=/Users/bsj/Desktop/Source
export MEDIA_DESTINATION=/Users/bsj/Desktop/Destination
rm -rf $MEDIA_SOURCE/*
rm -rf $MEDIA_DESTINATION/*
cd $MEDIA_SOURCE
cp $MEDIA_TEST/* .

# Rename files
#  Use -api QuickTimeUTC for MOV files
# If files already have a YYYY.MM.DD- prefix, remove it

exiftool  -ext mov -api QuickTimeUTC -ee  '-FileName<$CreateDate-${Filename;s/^\d\d\d\d.\d\d.\d\d-\d\d.\d\d.\d\d-(.*)\..*$/$1/}.%e' -d %Y.%m.%d-%H.%M.%S%%-c .

exiftool  --ext mov  -ee  '-FileName<$CreateDate-${Filename;s/^\d\d\d\d.\d\d.\d\d-\d\d.\d\d.\d\d-(.*)\..*$/$1/}.%e' -d %Y.%m.%d-%H.%M.%S%%-c .

# Move files
# DateTimeOriginal for PNG files, else CreateDate

exiftool -ext png -ee '-Directory<DateTimeOriginal' -d $MEDIA_DESTINATION/%Y/%Y-%m .

exiftool --ext png -ee '-Directory<CreateDate' -d $MEDIA_DESTINATION/%Y/%Y-%m .

Example Output Files
2023.11.25-12.58.21-GH010459-NeedleFish.mp4
2023.12.05-09.59.14-GOPR2922.jpg
2023.12.06-11.24.59-GOPR3029.jpg
2024.01.23-15.53.36-2024-01-23 15.53.37.heic
2024.02.01-17.47.36-2024-02-01 17.47.36.heic
2024.02.03-13.17.59-2024-02-03 13.17.59.png
2024.02.06-11.57.52-2024-02-06 11.57.52.mov
2024.02.26-07.58.53-GOPR2612.jpg

lundjohnson

#1
I think I found the -ext answer by searching the ExifTool Forum. I'm down from for exiftool commands to 3. I'll see if I can get it down to 1 exiftool command tomorrow.

Answers:

If you want different structured names for different file types, then it makes sense to have a separate command for each.  But the jpg commands may be combined:

exiftool "-filename<${FileModifyDate}-%%f.%%e" "-filename<${DateTimeOriginal}-%%f.%%e" -d "%dstdir%" "%srcdir%" -ext jpg %extraarg%

To put that all together, try this command
exiftool -o "Bearbeitet/" -fileOrder DateTimeOriginal "-filename=#%%1.3C.%%le" "-filename<${CreateDate}_test_%%1.3C.%%le" "-filename<${DateTimeOriginal}_test_%%1.3C.%%le" -d %%Y-%%m-%%d -ext jpg -ext mp4 -api QuicktimeUTC %1

The command will use the DateTimeOriginal if it exists, but fallback to CreateDate when it doesn't, like in MP4 files.


setopt interactivecomments
# Set up test files
export MEDIA_TEST=/Users/bsj/Desktop/TestSet
export MEDIA_SOURCE=/Users/bsj/Desktop/Source
export MEDIA_DESTINATION=/Users/bsj/Desktop/Destination
rm -rf $MEDIA_SOURCE/*
rm -rf $MEDIA_DESTINATION/*
cd $MEDIA_SOURCE
cp $MEDIA_TEST/* .

# Rename files
# Use -api QuickTimeUTC for MOV files
# If files already have a YYYY.MM.DD- prefix, remove it

exiftool  -ext mov -api QuickTimeUTC -ee  '-FileName<$CreateDate-${Filename;s/^\d\d\d\d.\d\d.\d\d-\d\d.\d\d.\d\d-(.*)\..*$/$1/}.%e' -d %Y.%m.%d-%H.%M.%S%%-c .

exiftool  --ext mov  -ee  '-FileName<$CreateDate-${Filename;s/^\d\d\d\d.\d\d.\d\d-\d\d.\d\d.\d\d-(.*)\..*$/$1/}.%e' -d %Y.%m.%d-%H.%M.%S%%-c .

# Move files
# DateTimeOriginal for PNG files, else CreateDate

exiftool -ee  '-Directory<CreateDate' '-Directory<DateTimeOriginal'  -d $MEDIA_DESTINATION/%Y/%Y-%m .

Phil Harvey

You need -api QuickTimeUTC for MOV fiels but not the others?  And you aren't renaming the PNG files?  This will require at least 2 commands, but you can do the moving and renaming together.  I can't easily test this out to be sure I didn't make a mistake, but something like this should work:

exiftool -ext mov -api QuickTimeUTC "-FileName<$MEDIA_DESTINATION"'/${DateTimeOriginal#;DateFmt("%Y/%Y-%m")}/$FileName' "-FileName<$MEDIA_DESTINATION"'/${CreateDate#;DateFmt("%Y/%Y-%m")}/$CreateDate-${Filename;s/^\d{4}.\d\d.\d\d-\d\d.\d\d.\d\d-(.*)\..*$/$1/}.%e' -d %Y.%m.%d-%H.%M.%S%%-c .

exiftool --ext mov "-FileName<$MEDIA_DESTINATION"'/${DateTimeOriginal#;DateFmt("%Y/%Y-%m")}/$FileName' "-FileName<$MEDIA_DESTINATION"'/${CreateDate#;DateFmt("%Y/%Y-%m")}/$CreateDate-${Filename;s/^\d{4}.\d\d.\d\d-\d\d.\d\d.\d\d-(.*)\..*$/$1/}.%e' -d %Y.%m.%d-%H.%M.%S%%-c .


The quoting is a bit complicated because $MEDIA_DESTINATION needs to be in double quotes to get interpolated by the shell (assuming Unix-type shell here).

I've removed the -ee because I don't think it should be necessary to extract only CreateDate and it will slow things down.

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