Windows Batch File – Copy Folder from an Existing Template with User Input

Paste the following code into a .bat text file to create a runnable script that copies an example template folder with contents to a new folder with a name entered by the user. There are an additional couple of lines that then rename and delete files in the new folder as an example of further customisation that could be automated.

@echo off
pushd %~dp0
REM request a Directory Name
set /p UserInput= "Create Directory: "
REM create directory using a source folder template
if not exist "%UserInput%" (
mkdir "%UserInput%"
xcopy /e SourceTemplateFolder "%UserInput%"
REM customise contents
rename "%UserInput%\Content.txt" NewContent.txt
del "%UserInput%\FileToDelete.txt"
)
popd

Leave a Reply

Your email address will not be published. Required fields are marked *