'Creating a batch script which takes inputs from the user and creates folder structures

Cobra kai_______Season 01_______S01E01
         |               |______S01E02
         |____Season 02  |______S01E03
         |               |______S01E04
         |____Season 03  |______S01E05
         |               |______S01E06
         |____Season 04  |______S01E07
                         |______S01E08
                         |______S01E09
                         |______S01E10
                     

Above is my desired folder structure.I need to create a batch script which takes following inputs from the user and creates the directories accordingly.

inputs:

  (1) Tv series name
  (2) How many seasons
  (3) How many episodes in each season

Below is what i tried so far,

@echo off


set /p name="Enter Tv series name : "
set /p s="How many seasons? : "
for /l %%i in (01,1,%s%) do set /p ep="How many episodes in season 0%%i? : "

mkdir "%name%"
for /l %%i in (01,1,%s%) do md "%name%"/"Season 0%%i"

This worked to the point where it creates below structure

Cobra kai_____Season 01
         |             
         |____Season 02
         |             
         |____Season 03
         |             
         |____Season 04

What i can't figure out is how to continue this script to create subfolders for episodes inside each season.How can i achieve this? Sorry for poor english.



Solution 1:[1]

Here's an example for you:

@echo off
setlocal enabledelayedexpansion
set /p "series=Enter Series Name? "
set /p "seasons=How Many seasons of %series%? "
for /l %%a in (1,1,%seasons%) do (
    set /p "episodes%%a=How many episodes for season %%a?
    for /l %%f in (1,1,!episodes%%a!) do mkdir "%series%\Season %%a\S%%aE%%f">nul 2>&1
)

If you want to add 0 before all single digit numbers:

@echo off
setlocal enabledelayedexpansion
set /p "series=Enter Series Name? "
set /p "seasons=How Many seasons of %series%? "
for /l %%a in (1,1,%seasons%) do (
    set /p "episodes%%a=How many episodes for season %%a?
    for /l %%f in (1,1,!episodes%%a!) do (
         if %%a lss 10 (
            set "_se%%a=0%%a"
          ) else (
            set "_se%%a=%%a"
         )
         if %%f lss 10 (
            set "_ep%%f=0%%f"
          ) else (
            set "_ep%%f=%%f"
         )
         mkdir "%series%\Season !_se%%a!\S!_se%%a!E!_ep%%f!"
     )
 )

It is however not at all required to add the array references (well, not even a real array, but anyway.) I personally just like keeping track of them because you can again use them later, in other scenarios. So without:

@echo off
setlocal enabledelayedexpansion
set /p "series=Enter Series Name? "
set /p "seasons=How Many seasons of %series%? "
for /l %%a in (1,1,%seasons%) do (
    set /p "episodes%%a=How many episodes for season %%a?
    for /l %%f in (1,1,!episodes%%a!) do (
         if %%a lss 10 (
            set "_se=0%%a"
          ) else (
            set "_se=%%a"
         )
         if %%f lss 10 (
            set "_ep=0%%f"
          ) else (
            set "_ep=%%f"
         )
         mkdir "%series%\Season !_se!\S!_se!E!_ep!"
    )
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1