Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
@WesSayeed I'm not sure what you mean. Wouldn't that just delete all the folders? I'm looking to create folders from 9 all the way to 122(or how many ever the number of lectures that are there). – Manish 21 hours ago
    
Since you specifically mention batch and script files I won't post this as an answer, but real super users know that it's much easier to just get the right tool for the job instead of writing your own ;). Just use a renaming tool and you can probably figure this out in less than a minute, including the download. I've personally used Rename Master and Bulk Rename Utility (contains ads) and both can handle this and many other annoying file and folder operations. (I am not affiliated with either tool.) – Lilienthal 1 hour ago

4 Answers 4

up vote 19 down vote accepted

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.

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

share|improve this answer
    
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? And many thanks! – Manish 21 hours ago
    
@Manish yes, you'd need to cd to the folder first. – LPChip 21 hours ago
    
No. Just change the md Lec-%%i to md C:\Dropbox\Development\Lec-%%i – DavidPostill 21 hours ago
2  
@DavidPostill the question asks from 9 up to. so that would be (9,1,120). you may want to edit your question. – LPChip 21 hours ago
1  
@Manish bash version: for i in {9..120}; do mkdir Lec-$i; done; - or replace {9..120} with `seq 9 120` for the more portable version. – Bob 16 hours ago

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

share|improve this answer
1  
+1 for teaching me something I didn't know. :) – LPChip 10 hours ago
    
The animation (".gif") is rather a nice touch, but repeating it over and over and over and over... endlessly, is very annoying. – Kevin Fegan 8 hours ago
2  
@KevinFegan I disagree. Looped GIFs makes sure the user (you) get to actually see the animation without reloading the page and scrolling down quickly to try and see it. Most browsers don't offer GIF control buttons. – phyrfox 2 hours ago
    
awesome answer and just stop watching after you get the point! – happytime harry 2 hours ago
    
thanks everyone glad to help. Looping because, it forces one to watch and understand whats happening. And yes @happytimeharry I am trying to stop watching it myself :D – shahid 38 mins ago

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
share|improve this answer
3  
It is nice of you to point this out, but it doesn't answer the question... – DavidPostill 21 hours ago
1  
@DavidPostill. I agree, which is why I worded it the way I did. But it's MUCH better than creating folders 1 by 1. Perhaps I should delete the answer and make it a comment? – TTT 20 hours ago

You might find that if you create numbered folders named like this, they won't display in the proper (expected) sort order:

C:\Dropbox\Development> dir /b
Lec-10
Lec-100
Lec-101
Lec-102
Lec-103
Lec-104
Lec-105
Lec-106
Lec-107
Lec-108
Lec-109
Lec-11
Lec-110
Lec-111
Lec-112
Lec-113
Lec-114
Lec-115
Lec-116
Lec-117
Lec-118
Lec-119
Lec-12
Lec-120
Lec-13
Lec-14
Lec-15
Lec-16
Lec-17
Lec-18
Lec-19
Lec-20
Lec-21
...
Lec-89
Lec-9
Lec-90
Lec-91
...

The problem is, the number portion of the foldernames is variable width, which affects how the folders are sorted.

If it's important to you that the folders are sorted properly, use the batch file below to create folders with the numbered portion of the foldernames padded with "0's" (zero's) so that all numbers are the same length, like this:

C:\Dropbox\Development> dir /b
Lec-009
Lec-010
Lec-011
Lec-012
Lec-013
Lec-014
Lec-015
Lec-016
Lec-017
Lec-018
Lec-019
Lec-020
Lec-021
...

Here is the batch file:

@echo off

for /L %%f in (9,1,120) do call :work 000%%f
goto :EOF


:work

set "dx=%~1"
set "dx=%dx:~-3%"

md "C:\Dropbox\Development\Lec-%dx%" >nul 2>&1

set "dx="
goto :EOF
share|improve this answer
    
How they sort is tool-dependent. Explorer (and most other file managers) will sort them intuitively, with Lec-10 coming after Lec-9. – afrazier 44 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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