changing file extension from UPPER CASE to lower case

Started by ryerman, April 02, 2012, 08:07:16 AM

Previous topic - Next topic

ryerman

While trying to  standardize JPEG file extensions (change JPEG to JPG and use lower case only) I found something that surprised me.

This command line:
1. exiftool -filename=%f.jpg -xpsubject=something "C:/file.JPG"
returns an error:
Error: 'C:/file.jpg' already exists - C:/file.JPG

However, this command line:
2. exiftool -filename=%f.jpg -xpsubject=something "C:/file.jpg"
updates successfully.

But C:/file.jpg "exists even more", if you get my meaning!

This seems inconsistent.  I'm glad the 2nd command works but I don't understand why there is no "file already exists" error.
But more importantly (to me), if command #2 works why can't command #1 rename the file using a lower case extension?

Jim
Windows 10 Home 64 bit, Exiftool v12.61

Phil Harvey

Hi Jim,

ExifTool doesn't try to rename the file if the name is the same as the original, so the 2nd command does nothing to the file name.

Command number 1 doesn't work because on a case-sensitive filesystem "file.JPG" is a different file which would be deleted by this command.  This would be bad.  On Windows, apparently "file.jpg" and "file.JPG" are the same file, but ExifTool doesn't know this.

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

ryerman

Hi Phil.

Thanks for the quick and clear response.

The command line was part of a script-written ArgFile.  My work-around was to use the -if option with the FileExtension composite tag and some additional -execute "blocks" devoted to extension standardization.

That's when I said: "Phil knew I'd need that FileExtension tag.  It's like he can read my mind!" ;)

Jim
Windows 10 Home 64 bit, Exiftool v12.61

Phil Harvey

Hi Jim,

Nice to see that someone appreciates the -ext option.  I wince every time I see someone type "*.jpg".

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

e2012

I'm sorry to continue this thread but I didn't found a solution to the OP problem for myself. How does it work with the -if construction? I failed so far because I guess I don't know the syntax especially when embedded in a DOS batch script.

I want to change and lower the extension from all via the Windows context menu handed over jpg/jpeg files within a batch file from *.JPG|*.JPEG|*.jpeg into *.jpg. If a file has already the *.jpg extension exiftool should keep it.

This does not work:

:loop
exiftool.exe -filename=%%f.jpg -ext JPG -ext JPEG -ext jpeg %1
shift
goto loop

Is there a way to accomplish? Maybe like this?

:loop
exiftool.exe -filename=%%f.jpg -if '$ext eq "JPG"' %1
exiftool.exe -filename=%%f.jpg -if '$ext eq "JPEG"' %1
exiftool.exe -filename=%%f.jpg -if '$ext eq "jpeg"' %1
shift
goto loop

A bonus would be to process only jpg/jpeg files and ignore others.

Phil Harvey

You could try this:

exiftool -filename=%%f.jpg -ext jpg -ext jpeg -if "$filename!~/\.jpg$$/" %1

This should rename only files which do not end in ".jpg" (lower case).  The -ext option is case insensitive, which is why your first idea didn't work.

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

ryerman

Quote from: Phil Harvey on December 13, 2012, 02:22:43 PM
You could try this:

exiftool -filename=%%f.jpg -ext jpg -ext jpeg -if "$filename!~/\.jpg$$/" %1

My testing of that command gives an error if the file extension is JPG (upper case).

If we get a little tricky, Exiftool can standardize JPEG file extensions  from "JPG" and "JPEG" (with any combination of upper and lower case letters)  to "jpg".
Try a DOS batch script with this Exiftool command line:
exiftool -ext jpg -ext jpeg -if "$FileExtension ne 'jpg'" -filename=%%f.jpgtemp %1 -execute -ext jpgtemp -filename=%%f.jpg "%~d1%~p1%~n1.*"

FileExtension is a composite tag which is available by using the sample config file.

Jim
Windows 10 Home 64 bit, Exiftool v12.61

Phil Harvey

Quote from: ryerman on December 14, 2012, 12:34:13 AM
My testing of that command gives an error if the file extension is JPG (upper case).

Thanks Jim,

Right.  I didn't think about this, but on case-insensitive filesystems (where "XXX.jpg" is the same file as "XXX.JPG"), ExifTool won't let you do this rename since the destination file already exists.

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

e2012

Quote from: ryerman on December 14, 2012, 12:34:13 AM
exiftool -ext jpg -ext jpeg -if "$FileExtension ne 'jpg'" -filename=%%f.jpgtemp %1 -execute -ext jpgtemp -filename=%%f.jpg "%~d1%~p1%~n1.*"

I don't really understand "%~d1%~p1%~n1.*" but I guess it removes the temp at the end somehow. I came up with this solution:

exiftool -ext jpg -ext jpeg -filename=%%f_tmp.jpg %1
set FILENAME=%1
set FILENAME=%FILENAME:~0,-4%
set FILENAME=%FILENAME%###
set FILENAME=%FILENAME:.###=###%
set FILENAME=%FILENAME:###=%
exiftool -ext jpg -filename=%FILENAME%.jpg %FILENAME%_tmp.jpg

ryerman

Quote from: e2012 on December 14, 2012, 07:39:42 PM
....I don't really understand "%~d1%~p1%~n1.*" but I guess it removes the temp at the end somehow....
%~d1%~p1%~n1 expands %1 in a DOS batch file to the fully qualified path, minus the extension.  Details are here.

I'm glad you found a solution.
I didn't realize you wanted to rename the files.  Your script appends "_tmp" to JPEG filenames so "filename.jpg" becomes filename_tmp.jpg".

Jim
Windows 10 Home 64 bit, Exiftool v12.61

e2012

Quote from: ryerman on December 14, 2012, 11:50:26 PMYour script appends "_tmp" to JPEG filenames so "filename.jpg" becomes filename_tmp.jpg".

That's only the first part of my script. The second does the same than your -execute command. I just found another way to cut off the extension from %1 but your solution is much faster and elegant so I use it now.

Thanks for the link. It will come handy.