Brian
Brian

Reputation: 558

Batch file to rename files

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!

Upvotes: 3

Views: 2642

Answers (1)

jeb
jeb

Reputation: 82192

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!
)

Upvotes: 7

Related Questions