Daily Archives: November 6, 2022

Windows Batch File – to create an empty folder structure in the same folder

Published by:

Paste the following code into a .bat text file to create a runnable script that makes a new empty folder structure within the same directory by double-clicking the file or running from the command line. You can change the CALL lines to reflect the folder names you require.

@ECHO OFF
TITLE Make Folders
REM use path of script %~dp0 as working directory 
REM this ensures that working directory is set expicitly
REM if run from CMD prompt the script path might be otherwise ignored
pushd %~dp0
ECHO Making Empty Folder Structure 
CALL :MakeFolder My-Config
REM create a folder with a space in the name use quotes "My Config"
CALL :MakeFolder My-Desktop\Sub-folder
REM create a sub folder
CALL :MakeFolder My-Documents
CALL :MakeFolder My-Downloads
CALL :MakeFolder My-Music
CALL :MakeFolder My-Pictures
CALL :MakeFolder My-Videos
popd
TIMEOUT 5
EXIT /B %ERRORLEVEL%
REM
REM create folder function
:MakeFolder 
SET fldr=%~1
if not exist %fldr% MD %fldr%
EXIT /B 0