Batch file to rename files

batch-file

Solution

If your filenames start all with `EXP_1` it's easy.

setlocal EnableDelayedExpansion
for %%A in (EXP_1*.XM_) do (
  set "filename=%%A"
  set "newName=EXP_!filename:~5!"

  rem ** remove the ECHO when it seems to work
  ECHO ren !filename! !newName!
)

Problem

We have a couple of thousand files in a directory named like this: ``` EXP_10000021.XM_ ``` And need to remove the leading 1 so the new file name is: ``` EXP_0000021.XM_ ``` I'm no good with batch files - any help would be appreciated!

Original source