ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: JanK on August 14, 2011, 06:45:01 AM

Title: Rename Files in order to DateTimeOriginal
Post by: JanK on August 14, 2011, 06:45:01 AM
Hello,

I have a few photos with different Filenames because of different cameras but belongs to the same event.
Filenames are "IMG_xxxx.jpg" ; "Pxxxxxxx.jpg" ; "DSCFxxxx.jpg" ; "CIMGxxxx" (x is the continuous number)

I want to rename the files like this:
001_FixNameOfMyEevent_YearFromMetadata_PhotographersName.jpg


Has anyone an idea how I can do this?

Thanks
Jan
Title: Re: Rename Files in order to DateTimeOriginal
Post by: Phil Harvey on August 14, 2011, 07:45:17 AM
Hi Jan,

Without creating user-defined tags to speed up the process, this may be done using a series of exiftool commands:

1) exiftool "-filename=%1.3C_FixNameOfMyEvent_${datetimeoriginal}.%e" -d %Y -fileorder datetimeoriginal# DIR

2) exiftool "-filename=%f_Maik.%e" -if "$model =~ /IXUS 80 IS/" DIR

3) exiftool "-filename=%f_Lisa.%e" if "$model =~ /Nikon/" DIR

4) etc

Notes:

i) Use single quotes around the -filename argument if you are on Mac or Linux, or double quotes as above on Windows.

ii) The "=~" operator matches a case-sensitive substring, so make sure your case is correct.

iii) DIR is the name of the directory containing the images.  Add the -r option to also process files in sub-directories.

- Phil
Title: Re: Rename Files in order to DateTimeOriginal
Post by: JanK on September 06, 2011, 01:46:48 PM
Hi Phil!

Sorry at the moment I have to little time to test your tips. Now I tried it but it seems there is a mistake.

The comand
exiftool "-filename=%1.3C_FixNameOfMyEvent_${datetimeoriginal}.%e" -d %Y -fileorder datetimeoriginal# DIR
will generate this output
Quote001_FixNameOfMyEvent_.JPG

But because I am on a Mac I entered it with single quotes like your discription. So I thought it will now create the year in the filename
exiftool '-filename=%1.3C_FixNameOfMyEvent_${datetimeoriginal}.%e' -d %Y -fileorder datetimeoriginal# DIR
But the output now was
Quote001_FixNameOfMyEvent_${datetimeoriginal}.JPG

I tried to search your documentation but I can't find anything. Not even comprehand the code in your example from August 14, 2011, 07:45:17 AM. It use a very complicated structure. I search so long but the documentation looks not very clear. Is there a full documentation where I can simple find anything that I need or is there a book which I can buy?

Thanks
Jan
Title: Re: Rename Files in order to DateTimeOriginal
Post by: Phil Harvey on September 06, 2011, 06:52:29 PM
Quote from: JanK on September 06, 2011, 01:46:48 PM
exiftool '-filename=%1.3C_FixNameOfMyEvent_${datetimeoriginal}.%e' -d %Y -fileorder datetimeoriginal# DIR
But the output now was
Quote001_FixNameOfMyEvent_${datetimeoriginal}.JPG

Ooops, sorry, my mistake.  You need to do this instead:

exiftool '-filename<%1.3C_FixNameOfMyEvent_${datetimeoriginal}.%e' -d %Y -fileorder datetimeoriginal# DIR

The < operator is necessary (as opposed to =) when we are copying a value from another tag.

QuoteIs there a full documentation where I can simple find anything that I need or is there a book which I can buy?

The documentation and examples should have pointed out this problem fairly quickly.  The application documentation (https://exiftool.org/exiftool_pod.html) covers all of this, but it is very concise and assumes familiarity with the command line, so it is not best for everyone.  Sorry, there is no book that covers this yet.

- Phil
Title: Re: Rename Files in order to DateTimeOriginal
Post by: JanK on October 22, 2011, 05:36:28 PM
I try to separate your commands because I will change the filename to have the year at the end. So I will have:
001_FixNameOfMyEevent_PhotographersName_YearFromMetadata.jpg

At first I try to explain your command line (could you check if I'm right?)
exiftool '-filename<%1.3C_FixNameOfMyEvent_${datetimeoriginal}.%e' -d %Y -fileorder datetimeoriginal# DIR

-filename is the argument for setting the filename
< is because the filename is generated from another tag
%1.3C is the first command for the filename (The Number starts with 1 and has three digits)
_FixNameOfMyEvent_ is a static name that would be attached to the filename (only when I write it direct behind the %1.3C; otherwise I have to use %f)
${datetimeoriginal} Is for attaching the date
. is a static dot
%e is the original file extension
-d is the argument for defining the format of the date (in this case it is used for ${datetimeoriginal})
%Y the date format is only the Year
-fileorder is the argument for the order in which the files are processing
datetimeoriginal the order is datetimeoriginal
# no idea

I try to rewrite it so the year is at the end
1) exiftool "-filename=%1.3C_FixNameOfMyEvent.%e" -fileorder datetimeoriginal# DIR
2) exiftool "-filename=%f_Maik.%e" -if "$model =~ /IXUS 80 IS/" DIR
3) exiftool "-filename=%f_Lisa.%e" if "$model =~ /Nikon/" DIR
4) exiftool "-filename=%f_${datetimeoriginal}.%e" -d %Y DIR

Is this right? Any mistakes? Now I have to use four command lines?

P.S I copyed the part 2) and 3) from your post. But there must be a mistake. Terminal says "123 files failed condition". That are all files. But some files should been matched. I used "model" and "Model" The Model is "Canon DIGITAL IXUS 500"
Title: Re: Rename Files in order to DateTimeOriginal
Post by: Phil Harvey on October 22, 2011, 06:41:26 PM
Your breakdown of the command line is correct.

Quote from: JanK on October 22, 2011, 05:36:28 PM
# no idea

A trailing # symbol after a tag name disables the print conversion.  In this case, we must disable the print conversion because you have set it to convert all date/time tags to the year only with -d %Y.

QuoteI try to rewrite it so the year is at the end
1) exiftool "-filename=%1.3C_FixNameOfMyEvent.%e" -fileorder datetimeoriginal# DIR
2) exiftool "-filename=%f_Maik.%e" -if "$model =~ /IXUS 80 IS/" DIR
3) exiftool "-filename=%f_Lisa.%e" if "$model =~ /Nikon/" DIR
4) exiftool "-filename=%f_${datetimeoriginal}.%e" -d %Y DIR

Is this right? Any mistakes? Now I have to use four command lines?

Close.  You made the same mistake I did with command 4.  You must use a < instead of = here or else the literal ${datetimeoriginal} will become part of the file name.  The quoting is correct for Windows, but if you are on Mac or Linux you need single quotes.  Also, replace DIR with the actual directory name when you run the command.

But you can do this in 3 commands instead of 4:

1) exiftool "-filename=%1.3C_FixNameOfMyEvent.%e" -fileorder datetimeoriginal# DIR
2) exiftool "-filename<%f_Maik_${datetimeoriginal}.%e" -if "$model =~ /IXUS 80 IS/" -d %Y DIR
3) exiftool "-filename<%f_Lisa_${datetimeoriginal}.%e" if "$model =~ /Nikon/" -d %Y DIR

Or, you could do it with 2 commands if a separate numbering scheme for the Maik and Lisa images would be OK:

1) exiftool "-filename<%1.3C_FixNameOfMyEvent_Maik_${datetimeoriginal}.%e" -if "$model =~ /IXUS 80 IS/" -d %Y -fileorder datetimeoriginal# DIR
2) exiftool "-filename<%1.3C_FixNameOfMyEvent_Lisa_${datetimeoriginal}.%e" if "$model =~ /Nikon/" -d %Y -fileorder datetimeoriginal# DIR

QuoteP.S I copyed the part 2) and 3) from your post. But there must be a mistake. Terminal says "123 files failed condition". That are all files. But some files should been matched. I used "model" and "Model" The Model is "Canon DIGITAL IXUS 500"

Oh.  The -if argument should be "$model =~ /IXUS 500/" to match the IXUS 500.

- Phil
Title: Re: Rename Files in order to DateTimeOriginal
Post by: JanK on October 23, 2011, 03:41:43 AM
Thanks!
It did not work because I did not use single quotes (I'm on Mac only). No it works great.

I will use your "Three times Terminal" Option. I need a sequential number of all images. Maybe on some celebration several people took pictures. I will sort this in hierarchically sequenze but will not lost the persons name from which the pictures where taken. In the past I sorted it in different folders. But when I show it to my family folder by folder I jumped around in the timeline. My goal is to bring all pictures to nearly to the same "datetimeoriginal" (I asked this in another topic) and then rename the filenames to hierarchical numbers shown in this topic  (Very cumbersum because no one set a correct time in his camera. Horrible! ;) )

Both arguments for the -if works. '$model =~ /IXUS 500/' and '$model =~ /Canon DIGITAL IXUS 500/'
When reading exif information with exiftool -G -s PICTURE.jpg the output is
Quote[EXIF]          Model                           : Canon DIGITAL IXUS 500
So I'm a little confused why your '$model =~ /IXUS 500/' is working. Does ~ in this case means "approximately" so a part from the whole Model name "Canon DIGITAL IXUS 500" is "IXUS 500" and so it works as a shortcut? Maybe "DIGITAL IXUS" will work as well or "GITAL IXU"?

So for now I have all information to realize my plan. Next step will be to built a little tool for doing this in some graphics way because I have a lot of pictures to re-sort. Do you have some tips which way I should use to bring the Terminal Commands in a GUI on MAC? For example XCODE or what would be the best for me? I now I still have a lot to learn. I have some very Basics in Actionscript, Delphi and HTML/CSS. I think I can do it

Thanks
Jan
Title: Re: Rename Files in order to DateTimeOriginal
Post by: Phil Harvey on October 23, 2011, 07:25:23 AM
Quote from: JanK on October 23, 2011, 03:41:43 AM
So I'm a little confused why your '$model =~ /IXUS 500/' is working. Does ~ in this case means "approximately" so a part from the whole Model name "Canon DIGITAL IXUS 500" is "IXUS 500" and so it works as a shortcut? Maybe "DIGITAL IXUS" will work as well or "GITAL IXU"?

This is a Perl regular expression, and the way it is used here means:  If "IXUS 500" is a substring of $model.

QuoteDo you have some tips which way I should use to bring the Terminal Commands in a GUI on MAC?

Check the programming resources on the ExifTool home page for some examples of calling ExifTool from various languages.

- Phil
Title: Re: Rename Files in order to DateTimeOriginal
Post by: JanK on November 15, 2011, 04:19:15 PM
I noticed something. Why does the file renaming does not affect avi files? Avi files also have an DateTimeOriginal so it should be renamed too. But the filename is not touched.

And is there a possibility to to delete the file number (001, 002,...) in front of the filename and generate a new continuous number before the rest of the file name? It is when I delete some files. Then I have 0001_Name, 0002_Name, 0004_Name
The 0003 was deleted. So I will only regenerate the filenumber but not the rest of the file.
Title: Re: Rename Files in order to DateTimeOriginal
Post by: Phil Harvey on November 15, 2011, 06:37:20 PM
Quote from: JanK on November 15, 2011, 04:19:15 PM
Why does the file renaming does not affect avi files?

This is FAQ number 16 (https://exiftool.org/faq.html#Q16)

QuoteAnd is there a possibility to to delete the file number (001, 002,...) in front of the filename and generate a new continuous number before the rest of the file name?

Yes.  The -w option documentation explains the details, but %.3f represents the original filename without the first 3 characters.

- Phil
Title: Re: Rename Files in order to DateTimeOriginal
Post by: JanK on November 19, 2011, 07:01:32 AM
QuoteBy default, ExifTool only processes writable file types... ...To force exiftool to process other files
Hmm. At first some files are not writable but than they are writable? What is right? Files can be writable or not. But nothing in the middle.

1. AVI is not listed with -listwf. Does this mean I can not change any Metadata or the filename with exiftool?

2. Does it mean only renaming or maybe changing -AllDates too which causes that the file needs to be rewritten?
Title: Re: Rename Files in order to DateTimeOriginal
Post by: Phil Harvey on November 19, 2011, 07:25:34 AM
AVI is not a writable format.  By this, I mean that ExifTool can not be used to change any data in the file itself.  Writable "pseudo" tags may still be changed -- this information is not stored in the file, but instead it is stored in the filesystem (the disk directory).

See the Extra Tags documentation (https://exiftool.org/TagNames/Extra.html) for more information.

- Phil