-1

So I have a lot of folders(1000+) and I want to add an incrementing number at the start of each one of them. The folder names contain spaces. I am on windows 10.

Example of folder names:

Folder number-one

Folder number-two

Folder number-three

Output wanted:

1000_Folder number-one

1001_Folder number-two

1002_Folder number-three

I've looked for similar articles but I didn't find something for my particular case.

  • Accounting for your statement, that you have over `1000` directories, and because you're incrementing from `1000` too, what do you want to rename the directory enumerated at position `1001`? – Compo Sep 13 '22 at 04:43

1 Answers1

0

The following code will rename all folders in c:\flrtest beginning with the letter "f" to an incremented number beginning with 1000.

I wrote it with the "f" restriction for two reasons:

(1) in case there were folders you did not want to change. To change all folders in c:\flrtest then just change line 3 from "c:\flrtest\f*" to "c:\flrtest"

(2) Allows running the script more than once without ill effect. If the "f" restriction is removed and the script is run more than once over the same set of directories it will yield results you probably don't want. The directories will end up with names such as "1000_1000_folderA" etc.

Since your folder will likely be somewhere other than "c:\flrtest" then just change this location in lines 3 & 7.

Hopefully this helps.

@echo off
set inc=1000
for /f "delims=" %%i in ('dir /a:d /b "c:\flrtest\f*"') do call :RenDir "%%i"
exit /b

:RenDir
ren "c:\flrtest\%~1" "%inc%_%~1"
set /a inc=inc+1
exit /b

Before running enter image description here

After running enter image description here

Removing the "f" restriction and running twice. Not so good. enter image description here

Bidder
  • 160
  • 6