ExifTool Forum

ExifTool => Newbies => Topic started by: wk002 on May 12, 2021, 04:27:25 PM

Title: Rename file extension based on metadata
Post by: wk002 on May 12, 2021, 04:27:25 PM
I want to rename all my photos using the date and time but I think I may have some photos that have the extension messed up in the filename. Is there a way to rename the files like in the documentation examples but use something from the metadata to correct file extensions? If I am reading the documentation right .%%e uses the existing file extension correct?

For instance in the past I may have accidentally renamed files with no extension. Now I have no idea if the file is damaged or just won't open because of a missing extension.


exiftool "-FileName<CreateDate" -d "%Y%m%d_%H%M%S.%%e" DIR
Title: Re: Rename file extension based on metadata
Post by: StarGeek on May 12, 2021, 04:45:36 PM
Try
exiftool "-Filename<$CreateDate.$FileTypeExtension" -d "%Y%m%d_%H%M%S" DIR

This won't process files that don't have an extension but you can add -ext "*" to process them (see FAQ #16 (https://exiftool.org/faq.html#Q16)).  I wouldn't suggest doing that for a directory that might have other file types that you don't want renamed.
Title: Re: Rename file extension based on metadata
Post by: wk002 on May 12, 2021, 07:13:32 PM
I will try that command. What about -tagsfromfile? I was looking through the documentation and found that switch. Though I am not totally sure that is a switch. 
Title: Re: Rename file extension based on metadata
Post by: StarGeek on May 13, 2021, 12:46:49 AM
From the docs on the -TagsFromFile option (https://exiftool.org/exiftool_pod.html#tagsFromFile-SRCFILE-or-FMT)
     As a convenience, -tagsFromFile @ is assumed for any redirected tags which are specified without a prior -tagsFromFile option.

When you're copying one tag into another in the same file, then -TagsFromFile isn't needed.