Skip to content

Instantly share code, notes, and snippets.

@emptypage
Created February 15, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emptypage/0794c6b483b927e768f0 to your computer and use it in GitHub Desktop.
Save emptypage/0794c6b483b927e768f0 to your computer and use it in GitHub Desktop.
A batch to create new file(s) from templates.
@echo off
setlocal enabledelayedexpansion
set TemplateDir=new-templates
REM # If no args are given, show help (and exit).
if "%1"=="" goto HELP
REM # Options
if /i "%1" == "/?" goto HELP
if /i "%1" == "/Y" (
set OverwriteAll=yes
shift /1
)
REM # Main
:LOOP
if "%1" == "" goto EXIT
set Template=NUL
for %%I in (%~dp0!TemplateDir!\*) do (
if "%%~xI" == "%~x1" (
set Template=%%I
goto FOUND
)
)
:FOUND
if exist %1 (
if /i "!OverwriteAll!" == "yes" goto DO
set /p Overwrite="%1 already exists. Overwrite? (Yes/No/All): "
if /i "!Overwrite:~0,1!" == "Y" goto DO
if /i "!Overwrite:~0,1!" == "A" (
set OverwriteAll=yes
goto DO
)
goto CONTINUE
)
:DO
copy /y /b "!Template!" "%~1"
:CONTINUE
shift /1
goto LOOP
:HELP
echo Create new file(s) from templates.
echo.
echo %~n0 [/y] filenames
echo.
echo filenames File name(s) to create (multiple values are available).
echo /y Don't ask on overwrite existing files.
echo.
echo Template files must be in the "!TemplateDir!" directory where the same
echo location of the program:
echo.
echo %~dp0!TemplateDir!
echo.
echo (This program is in the public domain.)
:EXIT
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment