Renaming Multiple Files in Multiple Subdirectories in Windows

I needed to change file extensions for a large set of files in multiple directories. This would normally be very tedious, or would require me to download a program that would never use again. Instead, I decided to work some command prompt magic.

Here is what I did. I created a batch file with the code below:

PUSHD .
FOR /R %%d IN (.) DO (
	cd "%%d"
	IF EXIST *.html (
		REN *.html *.aspx
	)
)
POPD
pause

To create a batch file, simply use a text editor to paste the code, and save the file with a .bat extension.

Make sure to replace *.html with the files you want to replace, and *.aspx with the files you want to replace those files with. The asterisk is a wild card. Lat, you would place that file in the folder where the files you want to rename is.

For example, if you are creating a backup and want to change all files with extension jpg to extension bak, you would use the following:

PUSHD .
FOR /R %%d IN (.) DO (
	cd "%%d"
	IF EXIST *.jpg (
		REN *.jpg *.bak
	)
)
POPD
pause

If you have any questions, feel free to leave me a comment.

Leave a comment

Your email address will not be published. Required fields are marked *