I need to create 1000 folders numbered 000 to 999 inside a directory. How can I do this using cmd (i.e. the Windows command line)?

  • It's problems like these I usually point people towards python for. Windows' command line is far from powerful, IMO it needs something to supplement it. – Phoshi Oct 19 '10 at 21:46
  • 1
    I just need to do it once, dont wanna install python just for that... – user11955 Oct 19 '10 at 21:47
  • 1
    Nah, you'll keep the Python around for other things ;) – Ignacio Vazquez-Abrams Oct 19 '10 at 21:52
for /l %i in (0,1,9) do md 00%i
for /l %i in (10,1,99) do md 0%i
for /l %i in (100,1,999) do md %i

Explanation from the documentation (i.e. type for /? at the command prompt):

Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

  %variable  Specifies a single letter replaceable parameter.
  (set)      Specifies a set of one or more files.  Wildcards may be used.
  command    Specifies the command to carry out for each file.
             Specifies parameters or switches for the specified command.


FOR /L %variable IN (start,step,end) DO command [command-parameters]

    The set is a sequence of numbers from start to end, by step amount.
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
    generate the sequence (5 4 3 2 1)
  • 1
    Is this a foreign tongue of some sort? Whatever, it works great! Thanks! – user11955 Oct 19 '10 at 21:58
  • Awesome! I just tried it. Would you mind explaining the syntax or giving a link to an explanation? – Christopher Bottoms Jan 27 '15 at 15:52
  • 1
    @ChristopherBottoms: I hope you have already figured the syntax out. but in case you still need it, go to cmd window and type for /? – Codism Sep 28 '15 at 5:03
  • phenomenal answer! – Brainmaniac Oct 29 '18 at 17:10

SET /P x=Insert the name of the place: 
SET /P y=Insert de number of the records: 

SET /A start=1
SET /A z=y+1

REM start the loop

REM make the directory
MKDIR %x%"__"%start%

REM increment by 1
SET /A start=start+1

REM if we're at the end, return
IF %start%==%z% (GOTO :EOF) ELSE (GOTO :MKDIR)
  • It works as a .bat file – NeoMati Jul 5 '17 at 7:30
  • it doesn't work. The OP wants names with 0 prefix (000-999), and he wants numbers only without any prefix. Your code produces numbers without 0 prefix, and you also added strange prefix. For example if name of the place is abc then you create abc"__"0, abc"__"1... abc"__"10... abc"__"999 – phuclv Jul 5 '17 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.