Replacing spaces in the exif model name

Started by rbak, February 11, 2024, 02:41:51 PM

Previous topic - Next topic

rbak

Hi all, I am new to the exiftool and still learning so please be gentle with me...  8)

I recently bought myself a NAS to store all the family photos that over the years have ended up on many different external drives. I am looking for a good way to organize my photos and for that reason I would like to rename my photos so the filename will be based on the actual date the photo was taken.

While checking the internet I found out that the exiftool seems to be the swiss army knife for this task. However it seems to have a bit steeper learning curve to understand all the possibilities compared to a swiss army knife :D

So far I have been able to figure out that the following command (on windows) works fine for me to rename the files in a specific directory (including any potential subdirectories):


exiftool -fileOrder DateTimeOriginal -r -d "%Y%m%d-%H%M%S%%-02.c.%%e" "-filename<$CreateDate" "DIR"


When a JPG photo was taken on the 11th of February 2024 at 19:46:32 and it is the only file taken in that second, the above command would result in a file with the following name: "20240211-194632-00.JPG" A 2nd phoo that was shot in exactly teh same second would result in a file with name "20240211-194632-01.JPG".

Although I expect the following command might actually make more sense (even though both end up with the same result):


exiftool -fileOrder DateTimeOriginal -r -d "%Y%m%d-%H%M%S" "-filename<$CreateDate%-02.c.%e" "DIR"


After all this is a cleaner way to use the date-time format. And in my opinion also easier to read


Next option I investigated was to add the exif camera model information in the actual file name. So I came up with the following:


exiftool -fileOrder DateTimeOriginal -r -d "%Y%m%d-%H%M%S" "-filename<$CreateDate-${model;}%-02.c.%e" "DIR"


With the example above and with my Nikon D750 I end up with a file name as follows: "20240211-194632-NIKON D750-00.JPG". So even though this seems to work fine I do not like the fact that there is a space that now ends up in the file name due to the model name in the exif being "NIKON D750".

Is there a way to manipulate the information retrieved from the exif and replace the space with a hyphen? So is there a way to manipulate this so I end up with "20240211-194632-NIKON-D750-00.JPG"? And of course I want this to work with all type of model names. So model names without spaces or even model names with multiple spaces.

By the way the reason I am thinking about using the model name in the file name is due to the fact that withing my family we use multiple devices to shoot photos. This way I can already identify based on the filename which camera or mobile phone the photo originates from.

StarGeek

Quote from: rbak on February 11, 2024, 02:41:51 PMIs there a way to manipulate the information retrieved from the exif and replace the space with a hyphen? So is there a way to manipulate this so I end up with "20240211-194632-NIKON-D750-00.JPG"? And of course I want this to work with all type of model names. So model names without spaces or even model names with multiple spaces.

You could do this by changing ${model;} into
${Model;tr/ /-/;tr(/\\?*:|"<>\0)()d}

Normally, the semicolon ; by itself will remove problem characters but because you're also swapping spaces->hyphens, it needs to be explicitly added.  See Advanced formatting feature, line starting "A default expression".
"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

rbak

#2
Can't figure out why but this throws an arror for me. Not sure how to interpret the code either. But in the mean time I decided to go for the following command:

exiftool -fileOrder DateTimeOriginal -r -d "%Y%m%d-%H%M%S" "-filename<$CreateDate-%02.c ${model;}.%e" "DIR"

This will result in the following file name: "20240211-194632-00 NIKON D750.JPG"

StarGeek

Oops, forgot there's a double quote in there.  Try this
${Model;tr/ /-/;tr(/\\?*:|\"<>\0)()d}

Or remove the quote, as I don't think that Model tag is likely to include one
${Model;tr/ /-/;tr(/\\?*:|<>\0)()d}

Quote from: rbak on February 12, 2024, 03:55:42 PMexiftool -fileOrder DateTimeOriginal -r -d "%Y%m%d-%H%M%S" "-filename<$CreateDate-%02.c ${model;}.%e" "C:\Users\rbak\Pictures\exiftool_test"

You could run this as a second command to change any spaces to hyphens
exiftool -fast3 -if3 "$Filename=~m/ /" "-Filename<${Filename;s/ /-/g}" /path/to/files/
"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

rbak

Quote from: StarGeek on February 12, 2024, 04:32:32 PMOr remove the quote, as I don't think that Model tag is likely to include one
${Model;tr/ /-/;tr(/\\?*:|<>\0)()d}

Great that did the trick :-)

So would it not be enough to just use the following for replacing only the spaces with a hyphen and ignore all other unsupported characters:

${Model;tr/ /-/;}

This seems to work fine for me as well. Is there a reason why the solution you propsed wil be better in certain situations?

StarGeek

You said
QuoteAnd of course I want this to work with all type of model names.

But models like these would cause problems
c:\exiftool -G1 -a -s -if "$Model=~/[\/\\?*:]/ or $Make=~/[\/\\?*:]/" -make -model -r Y:\!temp\!Metadata_Repository >temp.txt
======== Y:/!temp/!Metadata_Repository/Canon/CanonCanoScanFB630U.jpg
[IFD0]          Make                            : Canon Inc.
[IFD0]          Model                           : CanoScan FB630U/FB636U
======== Y:/!temp/!Metadata_Repository/Canon/CanonCanoScanN650U.jpg
[IFD0]          Make                            : Canon Inc.
[IFD0]          Model                           : CanoScan N650U/N656U
======== Y:/!temp/!Metadata_Repository/Canon/Canon_iR1018.jpg
[IFD0]          Make                            : Canon
[IFD0]          Model                           : Canon iR1018/1022/1023
======== Y:/!temp/!Metadata_Repository/Epson/EpsonCX3900.jpg
[IFD0]          Make                            : EPSON
[IFD0]          Model                           : EPSON CX3900/CX4000/DX4000
======== Y:/!temp/!Metadata_Repository/FLIR/FLIR_ONE.jpg
[IFD0]          Make                            : FLIR Systems AB
[IFD0]          Model                           : *
======== Y:/!temp/!Metadata_Repository/FujiFilm/FujiFilmFinePixJZ100.jpg
[IFD0]          Make                            : FUJIFILM
[IFD0]          Model                           : FinePix JZ100/JZ110
======== Y:/!temp/!Metadata_Repository/FujiFilm/FujiFilmFinePixJZ250.jpg
[IFD0]          Make                            : FUJIFILM
[IFD0]          Model                           : FinePix JZ250/JZ260
======== Y:/!temp/!Metadata_Repository/FujiFilm/FujiFilmFinePixXP200.jpg
[IFD0]          Make                            : FUJIFILM
[IFD0]          Model                           : FinePix XP200/XP210
======== Y:/!temp/!Metadata_Repository/Hasselblad/HasselbladCFV-50c.jpg
[IFD0]          Make                            : Hasselblad
[IFD0]          Model                           : Hasselblad CFV-50c/500
======== Y:/!temp/!Metadata_Repository/Hasselblad/HasselbladCFV_II50C.jpg
[IFD0]          Make                            : Hasselblad
[IFD0]          Model                           : CFV II 50C/907X
======== Y:/!temp/!Metadata_Repository/JVC/JVC_GR-DVX9x.jpg
[IFD0]          Make                            : JVC
[IFD0]          Model                           : GR-DVX9*
======== Y:/!temp/!Metadata_Repository/JVC/JVC_GR-DVxxx.jpg
[IFD0]          Make                            : JVC
[IFD0]          Model                           : GR-DV***
...
  104 directories scanned
 6787 files failed condition
  145 image files read

The inclusion of slashes or backslashes will create subdirectories.  For example, the "FinePix JZ100/JZ110" would end up with this
20240211-194632-FinePix JZ100/JZ110 D750-00.JPGThat is a filename of "JZ110 D750-00.JPG" in the newly created directory of "20240211-194632-FinePix JZ100"

The other characters listed are not legal for Windows filenames, though on the NAS will be more flexible about some of these.
"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

rbak

That makes sense. But would the semicolon at the end not take care of all the other non supported characters?

As I understand the semicolon in below would remove all non supported characters:

${model;}


As the space is a supported character the above would not remove it. As I want the space to be replaced by a hyphen I sort of expect that the following would do just that, and the semicolon at the end would also ensure any potential unsupported characters will be removed.

${Model;tr/ /-/;}


As I understand the following would replace the space with an hyphen (the ";tr/ /-/" part) and remove the specified characters "/", "\", "?", "*", ":", "|", "<", ">" and "null" (the ";tr(/\\?*:|<>\0)()d" part)

${Model;tr/ /-/;tr(/\\?*:|<>\0)()d}


But all of this is relatively new to me so maybe I am missing something in the syntax. Is there a tool where you can simply validate the syntax? That might help me and potentially others as well to better understand the syntax and the potential impact of adding a simple semicolon at the end.

Phil Harvey

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

StarGeek

As I said above

Quote from: StarGeek on February 11, 2024, 05:14:30 PMSee Advanced formatting feature, line starting "A default expression".

which says
QuoteA default expression of tr(/\\?*:|"<>\0)()d is assumed if the expression is empty (ie. ${TAG;}).

Quote from: rbak on February 13, 2024, 02:57:07 AMBut all of this is relatively new to me so maybe I am missing something in the syntax. Is there a tool where you can simply validate the syntax?

The syntax is the Perl language. Not something you can validate without actually running Perl.
"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