0

How to rename a large number of files within subfolders with the command prompt?

The files are currently named like this:

25738458-10000

25738458-20000

25738458-30000

25738458-100000

25738458-110000

25738458-120000

25738458-1000000

After renaming file names:

25738458-0010000

25738458-0020000

25738458-0030000

25738458-0100000

25738458-0110000

25738458-0120000

25738458-1000000

How can I achieve this?

Community
  • 1
  • 1

1 Answers1

0

Put this batch file in c:\windows and then open a cmd prompt in the root folder where you wish to rename all the files, and type the batch file name.

Currently it will echo the rename commands to the screen - remove the echo command to make it perform the renaming if it looks right.

@echo off
setlocal enabledelayedexpansion
set "pad=0000000"
for /r %%a in (*) do (
   for /f "tokens=1,* delims=-" %%b in ("%%~nxa") do (
      set "partb=%pad%%%c"
      echo ren "%%a" "%%b-!partb:~-7!"
   )
)
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68