26 February 2016

Batch Program to Change Multiple File Formats at Once

Leave a Comment
Batch Program to Change Multiple Extension Types at Once

Few days back, I had posted an article on how to rename multiple files at once. But that tutorial is limited to change file names only. What if you want to change multiple file formats at once? Of course, it would be a tedious task to change them one by one.

After a deep study of 1 hour, I was successful in creating a small batch program that can help you to change multiple file formats in just few seconds. This tutorial will guide you how to create that program. Additionally, you will learn the use of few commands and wildcards. So lets start now!


Steps to Create Batch Program


Before moving to the steps, first let me introduce you with batch programming. In short words, Batch is a scripting language which works in Windows, DOS and OS 2 platform and can be programmed in notepad or simply in windows command prompt shell. It consist of simple commands to be executed by command line interpreter. The file extension type of batch program is '.bat'. Now to create this program, you've to do some programming in batch language. Don't worry! I had already created this code for you. Simply copy this and then proceed with below steps.

@echo off
title change multiple file extensions at once
color 0
echo Welcome to this program
set /p a=Please enter the folder location where all files are saved:
echo Wait!
cd %a%
set /p b=Now enter the new format you wish to change -
rename *.* *.%b%
echo Done! Your format has been successfully changed!
pause>nul
echo Press any key to exit this program
pause>nul
exit
  1. First of all, open notepad by searching it from start menu. If you've notepad++ then use it instead of older version.
  2. Now copy above code inside notepad editor and press "CTRL+S" keyboard shortcut key to save it. Alternatively, you can click on "File>Save as" button.
  3. After this, save dialog box will appear. From here choose the location where you want to save the file (say I choose desktop) and type your file name with ".bat" as suffix. For example, "batchprogram.bat". Here "batchprogram" is file name and ".bat" is extension type. Without extension type, your program will not work.
  4. Finally hit "Save" button and that's it.
Now let me explain you the basic logic behind this batch program. Basically, there are important 2 commands in above code. First one is "cd", which is used to move command prompt to your desired location. Here it will move it to your folder location where all files are located. Second command is "ren", which is used to rename file name and extension type. The basic syntax for ren command is - "ren originalfile renamedfile". I think you already knew about it. Except these 2 commands, all other are basic and here is a short description for all of them.

CommandExplanation
echoecho is used to print text
titleThis will add title to your program
color 0aThis is used to set background and text color
set /pIt will get input from user and then save it in variable.
pause>nulThis command will pause screen until user press any key.
exitThis will exit the program.

Apart from these commands, I had also used asterisk wildcard (*). Asterisk can be replaced by any word, number, symbol or combination. In ren command, it will select all files and then change them to your desired format. However, there file name will remain same because of third asterisk wildcard. (See above code and ren command syntax) Still don't get it? Ask me in comment box.

One more important thing in above program is "%a%" and "%b%". As already explained, set command will take input from user and then save it in variable. Now to print that input we have to put it under question marks as like this %a% Basically, a and b are the variables from set command which will be printed in cd and ren commands respectively. Now I just hope that you've complete knowledge about this code.


How to Execute This Program


First of all, copy all files whose format you want to change and paste them in new folder. After that, open the batch program. It will display a welcome note as shown in below picture -

Program Welcome Message

Now type the folder location where all files are saved. For example, "C:\Users\Username\Desktop\Test". You can find your folder location from its address bar.

Find Folder Path Location

After this, write the new extension type without dot like - "PNG" (without dot symbol). Finally hit enter button and see the magic.

Execute Batch Program

Below is the simple preview of output -

Comparison Between Original and Changed Format

Many of you may be wondering that where this tricks can be helpful. My answer is, you can use it anywhere like to change the image formats which were created by your camera. Sometimes particular format files are acceptable by any software or online tool. This batch program will reduce your hand-work and you can easily do your job within few seconds.

Now its your turn to try this. If you have any question, please let me know in below comment box. For more interesting tutorials, stay connected. Love and blessings!

Leave A Comment