How can I create a list of named folders in Windows automatically?
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 tomd C:\Dropbox\Development\Lec-%%i
.
Note:
mkdir
is a synonym formd
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 tomd 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.
This won't be better than a script for your particular scenario, but it's kind of nice to know this when your folder names are unrelated: you can make multiple directories from the command line by separating them by a space:
C:\temp\animals>dir
Volume in drive C is Windows
Volume Serial Number is 82CB-BB0F
Directory of C:\temp\animals
11/16/2015 03:55 PM <DIR> .
11/16/2015 03:55 PM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 1,636,846,243,840 bytes free
C:\temp\animals>mkdir cats dogs penguins
C:\temp\animals>dir
Volume in drive C is Windows
Volume Serial Number is 82CB-BB0F
Directory of C:\temp\animals
11/16/2015 03:55 PM <DIR> .
11/16/2015 03:55 PM <DIR> ..
11/16/2015 03:55 PM <DIR> cats
11/16/2015 03:55 PM <DIR> dogs
11/16/2015 03:55 PM <DIR> penguins
0 File(s) 0 bytes
5 Dir(s) 1,636,846,178,304 bytes free