How can I create a list of named folders in Windows automatically?

So, I am studying an online course which has hundreds of sub lectures. I need to download the source code for each lecture in a corresponding sub-folder. With over 120 lectures, creating a sub-folder one by one is a painstaking process.

Here's my current folder structure:

enter image description here

Is there a way I can create all these sub-folders at once, along with the proper name, through a batch file or something similar.


How can I can create all these sub-folders at once, using my naming scheme?

If I were to create the sub-folders in a specific directory, such as C:\Dropbox\Development, would I need to cd to that directory first? Assuming I'm using the cmd shell?

To create the sub-folders (sub-directories) in a specific directory (that is not the current directory), you can do one of the following:

  • cd C:\Dropbox\Development first or
  • Change the md Lec-%%i command to md C:\Dropbox\Development\Lec-%%i.

Note:

  • mkdir is a synonym for md and can be used in its place.

Below I show both alternatives, first from a cmd shell (command line), and second using a batch file.

As a bonus (although not asked for in the original question) there is a bash shell alternative as well.


From a cmd shell:

cd C:\Dropbox\Development
for /l %i in (9,1,120) do md Lec-%i

or

for /l %i in (9,1,120) do md C:\Dropbox\Development\Lec-%i

From a batch file:

@echo off
cd C:\Dropbox\Development
for /l %%i in (9,1,120) do md Lec-%%i

Or

@echo off
for /l %%i in (9,1,120) do md C:\Dropbox\Development\Lec-%%i

Notes:

  • 9 is the start number. Change if necessary.
  • 1 is the step. Do not change this.
  • 120 the end number. Change if necessary to the number of the last directory you require.
  • To create files in another directory, you can either

    • cd C:\Dropbox\Development\Lec-%%i first or
    • change the md command to md C:\Dropbox\Development\Lec-%%i.

Is there a way to do a similar thing for Mac OSX from the Mac terminal?

From a bash shell:

for i in {9..120}; do mkdir Lec-$i; done; 

Or (for a more portable version)

for i in `seq 9 120`; do mkdir Lec-$i; done;

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • for - Conditionally perform a command several times.
  • md - Make Directory - Creates a new folder.

There is another easy way, for limited number of folders. May be Useful here Or for someone else.

In Windows we can make numbered folder names by creating a folder "lec(1)" and copy pasting it how many time we want, if we paste 10 time there will be 11 folders with names "lect(1)" to "lec(10) - Copy"

Only trick here is that the first folder must include parentheses (n), where n is the number from where numbering starts.

Windows includes "- copy" at the and of pasted folder name "lec(1) - Copy" :(

If you don't like it, just select all and rename first lec(1) -> lec-(1) or anything.

All folder's names will be adjusted and "- copy" will be removed ;)

  • Ctrl+C - Copy
  • Ctrl+V - Paste
  • F2 - rename
  • Enter - to finish renaming.
  • ESC- to cancel renaming.
  • Ctrl+A or Ctrl+UP to select folders.

enter image description here