ExifTool Forum

ExifTool => Newbies => Topic started by: fotgrafToday on March 05, 2025, 02:01:21 PM

Title: Renaming files
Post by: fotgrafToday on March 05, 2025, 02:01:21 PM
After spending several hours testing, I would like to ask for help.

I am trying to go through folders if images and add ,,-,, to the image name if the image had a rating.

Before: 20250109-00001.JPG
After: -20250109-00001.JPG


exiftool ,,-filename<Rating" -r

Works great to rename file with the rating, but can't figure out how to add original name and extension, not the ,,-,,
Title: Re: Renaming files
Post by: StarGeek on March 05, 2025, 02:16:56 PM
See Writing "FileName" and "Directory" tags (https://exiftool.org/filename.html) for help on renaming.

Just to be clear, you are only adding a minus sign prefix to the filename if the Rating exists?

You don't mention your OS, which is important.

Assuming Windows CMD (don't use Powershell)
exiftool -r -if "$Rating" -Filename=-%F /path/to/files/

If you are on Mac/Linux, change the double quotes to single quotes.

The %F (capital F) variable holds the filename+extension. This command will prefix any file that contains a Rating with the minus sign.
Title: Re: Renaming files
Post by: fotgrafToday on March 06, 2025, 10:25:37 AM
BRILLIANT  :)

Thank you very much StarGeek. This Worked perfectly!

What is the variable for the Rating in a given file if I wanted the Rating to be the prefix to any file?
Title: Re: Renaming files
Post by: StarGeek on March 06, 2025, 10:57:22 AM
You would use the name of the tag. But using a tag means that the operation changes from a simple assignment, which uses the equal sign, to a tag copy operation, which uses the greater/less than sign.

Additionally, because there isn't a space to separate Rating from the rest of the text, braces must be used around the tag name

exiftool -r -if "$Rating" "-Filename<${Rating}-%F" /path/to/files/

See FAQ #2 and #3 (https://exiftool.org/faq.html#Q2) for the commands used to find the tag names, not tag descriptions.
Title: Re: Renaming files
Post by: fotgrafToday on March 07, 2025, 03:37:41 AM
thank you for the quick answer.

I keep getting an error message (MacOSX)

exiftool -r -if '$Rating' -Filename=${Rating}-%F FOLDER
zsh: no such file or directory: -%F
Title: Re: Renaming files
Post by: greybeard on March 07, 2025, 05:14:39 AM
Quote from: fotgrafToday on March 07, 2025, 03:37:41 AMexiftool -r -if '$Rating' -Filename=${Rating}-%F FOLDER
zsh: no such file or directory: -%F

How about:

exiftool -r -if '$Rating' '-Filename<${Rating}-%F' FOLDER
Title: Re: Renaming files
Post by: StarGeek on March 07, 2025, 10:36:03 AM
Quote from: fotgrafToday on March 07, 2025, 03:37:41 AMI keep getting an error message (MacOSX)

exiftool -r -if '$Rating' -Filename=${Rating}-%F FOLDER
zsh: no such file or directory: -%F

While I did make the mistake of forgetting the quotes, that is not the command I used. Please re-read the very first line of that post.

@greybeard used the correct command for Mac/Linux.