Need help with move and rename script

Started by mixar, May 11, 2025, 06:29:17 PM

Previous topic - Next topic

mixar

I'm trying to move all my photos to new folders based on year and month. If I run the script below then that happens. However, I want to add a command to move files that have no DateTimeOriginal to M:\Photos\Sorted\NoDateTimeOriginal\ based on CreatedDate and into a year and month folder. Separately, I would like to rename all files based on YYMMDDHHMMSS and in case their are duplicates increment a # at the end.

I'm having trouble with all the parameters beyond what I have below and hoping for assistance. Thank you

.\ExifTool -m -r "-Directory<DateTimeOriginal" -d "M:\Photos\Sorted\%Y\%m" "M:\Photos\Test\"

StarGeek

#1
Since you want two different directories, you need to split the path out from the -d (-dateFormat) string and add a dollar sign in front of the tag names

exiftool -m -r "-Directory<M:\Photos\Sorted\NoDateTimeOriginal\$CreateDate" "-Directory<M:\Photos\Sorted\$DateTimeOriginal" -d "%Y\%m" "M:\Photos\Test"

This uses Note #1 under the -TAG[+-^]=[VALUE] option

QuoteMany tag values may be assigned in a single command. If two assignments affect the same tag, the latter takes precedence...

So using DateTimeOriginal takes priority if it exists, else it falls back to CreateDate

Make sure and use CMD, as this command will fail on PowerShell, though it might work if you change the double quotes into single quotes.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mixar

I appreciate the reply. I made 2 changes but also tried your way just to make sure. "exiftool" was mispelled and it appeared there was a missing " before the second -Directory.

Below is what I typed into cmd and the error that showed up.

C:\Program Files\ExifTool>

exiftool -m -r "-Directory<M:\Photos\Sorted\NoDateTimeOriginal\$CreateDate" "-Directory<M:\Photos\Sorted\$DateTimeOriginal" -d "%Y\%m" "M:\Photos\Test\"

Warning: Error opening file - M:/Photos/Test"
Error: File not found - M:/Photos/Test"
    0 image files updated
    1 files weren't updated due to errors

StarGeek

Quote from: mixar on May 12, 2025, 09:48:04 PMI appreciate the reply. I made 2 changes but also tried your way just to make sure. "exiftool" was mispelled and it appeared there was a missing " before the second -Directory.

Sorry, edited my post to fix that.

QuoteWarning: Error opening file - M:/Photos/Test"
Error: File not found - M:/Photos/Test"
    0 image files updated
    1 files weren't updated due to errors

Oops, that was something else I missed. The problem is with your image directory.

You cannot have a backslash before the quote as that will escape quote and make it part of the path. Notice how the error includes the trailing quote mark.

Either remove the quotes or remove the trailing backslash. Any of these should work. Internally, exiftool changes the backslashes to slashes (it's a Perl thing), so the quote won't be included if you have a slash instead of a backslash.
M:\Photos\Test
"M:\Photos\Test"
M:\Photos\Test\
M:/Photos/Test
M:/Photos/Test/
"M:/Photos/Test/"
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mixar

Making progress.

The 2 things this didn't do was rename  the files based on YYMMDDHHMMSS and in case their are duplicates increment a # at the end and put the photos with NoDateTimeOriginal into the folder in the script. Instead it put NoDateTimeOriginal files directly into M:\Photos\Sorted\.

StarGeek

Quote from: mixar on May 13, 2025, 03:40:03 PMThe 2 things this didn't do was rename  the files based on YYMMDDHHMMSS and in case their are duplicates increment a # at the end

To rename, you don't use Directory, you include the directory path when writing FileName. Here I used %-c for the copy number. This will prepend the copy number with a dash when a copy number is needed. Remove the dash if you don't want it.

exiftool -r "-FileName<M:\Photos\Sorted\NoDateTimeOriginal\$CreateDate%-c.%e" "-FileName<M:\Photos\Sorted\$DateTimeOriginal%-c.%e" -d "%Y\%m\%y%m%d%H%M%S" M:\Photos\Test\

Quoteput the photos with NoDateTimeOriginal into the folder in the script. Instead it put NoDateTimeOriginal files directly into M:\Photos\Sorted\.

I didn't catch that you were using the -m (-ignoreMinorErrors) option. From the docs
QuoteNote that this causes missing values in -tagsFromFile, -p and -if strings to be set to an empty string rather than an undefined value.

Copying from CreateDate to Directory or FileName is a -TagsFromFile operation, so adding the -m means that CreateDate will always exist, so exiftool will never fall back to using DateTimeOriginal.

See the -w (-TextOut) option for details on the file % codes (%c, %e). See Writing "FileName" and "Directory" tags for more details on writing to Filename/Directory and for the date/time % codes.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mixar

Just wanted to say thank you. That worked perfectly for me.