Windows – Batch rename removing second letter in filename

batch-fileexchangerenamewindows

I have about 300 .pst files that I have exported from Exchange 2010. Eventually, I'm going to import them into another Exchange/AD environment. In the original environment, the user names are as follows: FirstinitialMiddleInitialLastName i.e. Bart P. Smith would be bpsmith.

In the new environment, the user name are first initial last name. So, bsmith.

Instead of manually renaming each pst file for import does anyone know a way to batch rename each file in the directory, removing the second letter in the filename?

Thanks in advance.

Best Answer

Open a command prompt in the directory your .pst files are located in, and place the following file in that directory (save it as renamepst.cmd)

@echo off
for %%f in (*.pst) do call :renfile "%%f"
goto :eof

:renfile
set file=%1
echo rename %file% %file:~0,2%%file:~3,999%

This batch file has an echo command in place so that it doesn't actually perform any actions. If you are happy with the output after running renamepst.cmd in your command prompt window, then remove the echo from the last line, leaving rename %file% %file:~0,2%%file:~3,999% in place.

Please test before using this though!