Technology, life, programming, travel and money.

Converting file extensions to lower case

Recently I needed to convert a large number of photo file extensions to lower case. Doing this manually would take ages and wouldn’t be a fun job.

I wrote a quick batch file to look through all the sub-directories from the one it is executed from and change selected file extensions to lower case.

To use this script place the below code in a file called lowerCaseExtensions.bat. Put the batch file in the directory containing the files that you want changed and double click on it.

The script will loop through all the files in the directory, and will loop thought the files in all sub-directories and will change jpg, png and gif extension to lower case.

@echo off
setlocal
pushd .
goto :skip_functions
:toLower
	cd %1
	echo Processing %1
	ren *.JPG *.jpg 2>&1
	ren *.PNG *.png 2>&1
	ren *.GIF *.gif 2>&1
goto :EOF
:skip_functions
for /f %%i in ('dir /b/s/ad') do call :toLower %%i
popd
endlocal

You can easily customise this to change the file extensions of other file types to lower case.

This has been tested only on my Windows XP computer so I’d suggest you test it first on some copied files before you let it lose on your real ones.

Even if you aren’t specifically interested in the functionality that this batch file implements you might find it interesting to see how to implement a simple callable function in a batch file (:toLower), and how to implement ‘for’ loops.


Reader Feedback

5 Responses to “Converting file extensions to lower case”

  1. That’s good batch script. But you can achieve a more generalized and easy solution if you create VB Script file and since windows by default has cscript command line interpreter to execute vb scripts, you can easily call it from command line.

  2. Conan Hardtooth says:

    Harsh – Dude. (Cool name by the way…) Thanks for the suggestion for using VB script, but maybe you could go that extra little step and point us to a sample vb script that would change the case of files names and their extensions.

    That would be really helpful.

  3. worldwide says:

    It also works with Windows 7 ;-)

  4. uli says:

    for /r %x in (*.JPG) do ren “%x” “%~nx.jpg”

  5. uli says:

    unfortunately the script doesnt work, if the foldername has blanks in it…

Leave a Reply

Do NOT fill this !