Batch Rename/Replace File Extensions

Started by Mike, May 09, 2023, 11:26:58 PM

Previous topic - Next topic

Mike

Hi,

I normaly would expect the renamer to be the tool for my problem, but this doesn't seem to be implemented that way, so does anybody know a solution for the case we need to batch rename/replace file extensions?

I just discovered that more than 1000 image files (that have been in the database for a long time) are using an incorrect extension. They are actually WEBP files, but incorrectly use the JPG extension.

I tried an older app I found in the forum, that was meant for that, but it doesn't seem to work in the current iMatch.
Quote from: Jingo on December 21, 2017, 02:35:32 PMHi all... created a quick app that renames the extensions of files from within IMatch....

Any other ideas? Thanks in advance

Mario

#1
Please do not post questions in a board that is intended to post tips & tricks to other users.
Don't just pick any board when posting. Read the description under each board name before posting.

I will move your post there this time.

The Renamer does not change file extensions - for obvious reasons.
This would open a venue for users to shot themselves into the foot big time.

Why don't you do a simple

ren *.webp *.jpg
on a command prompt in the folder containing the files with the wrong extensions?
This changes the webp extension into jpg while keeping the original file name.
Quick and easy, no special tools required.

Select the folder containing the files in IMatch and press <Ctrl>+<C>
Open a Command Prompt from the START menu.
Type cd and then press <Ctrl>+<V> to insert the folder name. Press <Enter>.
Note: If the folder in on another drive, type in the drive letter followed by : first and press <Enter>.

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mike

#2
Thanks for the idea and yes, you are right, I shouldn't have posted the question on this board. Sorry!

Some aspects that make dealing with the extensions a bit difficult in my case:

  • The 1346 files are unfortunately extremely scattered (only one to three per folder). Executing commands in individual folders would hardly be more efficient than changing them manually.
  • The files are always among many others with the same JPG extension. This means that such a command would not identify them so that this would also harm others.
  • In iMatch they are all now marked and filterable, in Explorer not. I discovered them in the first place because they were the only ones that didn't have thumbnails in iMatch - in Explorer they did. Only later did I understand why.

I wanted to avoid having to install external tools, so your idea with the command suits me.

Possible steps:

  • Batch rename the files in question in iMatch so that they can be identified/found in Explorer. That's easy.
  • The command would have to only work on the Windows Explorer results and not on the entire contents of the folders containing the files in general. Possible? I haven't found a suitable solution on the internet yet.

bekesizl

Is there maybe a possibility in IMatch to make a list of filenames with full path of selected files to a textfile or clipboard?

This could be edited into a batch file to let Windows rename the selected files.
e.g.
Export:
c:\SomeFolder\SomeSubFolder\FileToRename.jpg
Edited command:
ren c:\SomeFolder\SomeSubFolder\FileToRename.jpg c:\SomeFolder\SomeSubFolder\FileToRename.webp

Mario

#4
QuoteIs there maybe a possibility in IMatch to make a list of filenames with full path of selected files to a textfile or clipboard?
Select the files in a File Window and press <Ctrl>+<C>

See: File Management in IMatch and here Keyboard Shortcuts

If you need more detailed control, you can e.g. use the Copy Data app or the Text Export feature.
Using the Text Exporter with some clever variables could even produce your entire Batch File.
For example, use this variable:
ren "{File.FullName}" "{File.FullName|replace:.jpg==.webp}"
This produces lines like:

ren "c:\images\beach.jpg" "c:\images\beach.webp"

For each file you drop onto the text exporter.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mike

Thank you both for the interesting approaches! 
I will try to implement that.

Mike

#6
At first glance everything seems simple, and yet even a small test does not seem to work. I saved the Batch-File as UTF-8, and also tried the ANSI format.

The test batch-file (without the dotted lines, of course) contains the following text. Other versions have also failed.

---------------------------------------
@echo off

ren "E:\TEST FOLDER\SUBFOLDER A\FILE A.jpg" "E:\TEST FOLDER\SUBFOLDER A\FILE A.webp"
ren "E:\TEST FOLDER\SUBFOLDER B\FILE B.jpg" "E:\TEST FOLDER\SUBFOLDER B\FILE B.webp"
ren "E:\TEST FOLDER\SUBFOLDER C\FILE C.jpg" "E:\TEST FOLDER\SUBFOLDER C\FILE C.webp"

pause
---------------------------------------

The cmd.exe response is:

syntax error.
syntax error.
syntax error.

What could be wrong with the lines?

  • The paths are correct as far as I can tell.
  • The lines are copied from the txt result of iMatch Text Exporter, where I used your code:
    ren "{File.FullName}" "{File.FullName|replace:.jpg==.webp}"
  • The export from iMatch took place as UTF-8.
  • In another version I even converted the exported txt file directly to a ".bat" but got identical results.
  • I tried the batch file in various places. Directly in the main folder, or in completely different places. Results were always the same.

Any idea what I could be doing wrong?

PS. The chatGPT open Ai recommends the same content for the batch file.

thrinn

Well, the help for the ren command (ren /?) tells me:

Sie können kein neues Laufwerk und keinen anderen Pfad für die Zieldatei angeben.
[You can not enter a new drive or path for the target].

So, try to use the following expression in the Text Exporter:
ren "{File.FullName}" "{File.NameExt|replace:.jpg==.webp}"
This will result in something on the lines of:
ren "D:\Users\Thorsten\Pictures\P1050640-2.jpg" "P1050640-2.webp"
Thorsten
Win 10 / 64, IMatch 2018, IMA

axel.hennig

I think it should be

--------------------------------------
@echo off

ren "E:\TEST FOLDER\SUBFOLDER A\FILE A.jpg" "FILE A.webp"
ren "E:\TEST FOLDER\SUBFOLDER B\FILE B.jpg" "FILE B.webp"
ren "E:\TEST FOLDER\SUBFOLDER C\FILE C.jpg" "FILE C.webp"

pause
---------------------------------------


Mario

My bad. The second argument of ren of course takes only a file name, not a path and file name.
The correct variable would thus be:

ren "{File.FullName}" "{File.NameExt|replace:.jpg==.webp}"


Note: When you rename files outside of IMatch that way, IMatch will lose track of the files and mark them as off-line.
You need to relocate them individually afterwards if you want to keep the associated data.

See Off-line Folders and Files
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mike

Thank you both! That was the solution. It works!

It was my first time trying to create a batch file in Windows, so I was a bit lost  ;)

Now I can try to apply this to the real files...

Mike

Quote from: Mario on May 10, 2023, 04:29:11 PMMy bad. 
Absolutely no problem!

Quote from: Mario on May 10, 2023, 04:29:11 PMNote: When you rename files outside of IMatch that way, IMatch will lose track of the files and mark them as off-line.
You need to relocate them individually afterwards if you want to keep the associated data.
I know that, only in this case, luckily, it won't be a problem.

Thanks!

thrinn

...but take extra care to read Mario's note about renaming files outside of IMatch! IMatch will not know that xyz.webp is the same file as xyz.jpg before. You mentioned about 1300 files scattered over multiple folders, and you will have to make a manual "Relocate" for each of these files.

I just found this rather old  thread with an App written by Jingo. Unfortunately, the attached ZIP file seems to be broken, but maybe Jingo can upload the App again - if it still works, that is.

[Edit: Just saw that you are aware of the Relocate - so forget what I wrote above]
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mike

I tested Jingo's app this morning but it doesn't seem to be working in the current iMatch. I was able to download and install it and I changed the extensions in it manually but nothing happened after clicking. The required files were of course selected.

Of course, it would be handy if the app worked and was available in iMatch. Who knows if or when we'll encounter any incorrect file extensions again.

At least I know the batch file solution now...

thrinn

I just tried the App again (after extracting it with 7Zip instead of the Windows built-in ZIP support) and it worked. The "Change from MOV to mp4" button only renames MOV files, but the "Change file extension" button respects the source and destination extensions I entered.
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

#15
Quote from: thrinn on May 10, 2023, 04:47:43 PMI just found this rather old  thread with an App written by Jingo.
This is what I mean. A 5 year old thread with an app downloaded about 20 times in total...

Having to change a large number of file name extensions is such a rare thing, it does not really make a use case for a built-in feature in IMatch. I don't know under which circumstances .WEBP files could end up with a .JPEG file extension, but I guess it's really a rare situation.

The Text Exporter did a good job (after I've fixed my mistake).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mike

Quote from: thrinn on May 10, 2023, 05:41:56 PMthe "Change file extension" button respects the source and destination extensions I entered.
I did exactly the same with no effect. Maybe I'll test that again sometime and see if I can discover the cause of the failure.


"I don't know under which circumstances .WEBP files could end up with a .JPEG file extension, but I guess it's really a rare situation."
I received some files that way, others come from downloads in the course of extensive research. Apparently similar things have happened in many places, whether accidental, systemic, or intentional for some purpose that escapes me.
Knowing what the occasional problem is, I'll be better able to prevent it in the future.


"The Text Exporter did a good job (after I've fixed my mistake)."
Yes, that's right

Jingo

Like Mario/Thrin mentioned, the app is many years old and written in kindness for a specific user purpose.  However, I just tested it and it still worked.. just change MOV to your extension and MP4 to whichever and click the CHANGE FILE EXTENSION button... if your selected files extension matches the new one, it will change it successfully!

Enjoy!