Make Lots of Directories with SMD.bat using Windows Batch


This is a simple batch script that I programmed many years ago. It demonstrates the idea of using shift parameters. The brackets ( and ) enable the expression of tree-like structures when making directories.

@echo off
:: https://helloacm.com

setlocal
if [%1] equ [] goto help

:work
  set supermd=%1
  if "%supermd%"=="(" goto error
  if "%supermd%"==")" goto error
  mkdir %supermd%
  echo Making "%supermd%"
  shift
  if "%1"=="" goto end
  if "%1"=="(" goto signin
  if "%1"==")" goto signout
  goto work
  
:signin
  cd "%supermd%"
  shift
  goto work
  
:signout
  cd ..
  shift
  goto work
  
:help
  echo.
  echo Usage:%0 a b ( c d e ) f g ( h i )
  echo.
  goto end
  
:error
  echo.
  echo Error!
  echo.
  
:end

endlocal

The latest directory name is stored using set, when “(” is parsed, the directory is updated and “)” allows one directory up which returns to its previous level. The shift will allow parsing the next available parameter until end of line.

Simple, but yet a compact example of using batch to make level-directories using one simple command.

The batch file can be downloaded at [github].

–EOF (The Ultimate Computing & Technology Blog) —

215 words
Last Post: Fibonacci Numbers, Windows Batch Programming Revisited
Next Post: Another Batch Utility: Reverse the Given Text

The Permanent URL is: Make Lots of Directories with SMD.bat using Windows Batch (AMP Version)

Leave a Reply