AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

batch-files

Expert-level Windows batch file (.bat/.cmd) skill for writing, debugging, and maintaining CMD scripts. Use when asked to "create a batch file", "write a .bat script", "automate a Windows task", "CMD scripting", "batch automation", "scheduled task script", "Windows shell script", or when working with .bat/.cmd files in the workspace. Covers cmd.exe syntax, environment variables, control flow, string processing, error handling, and integration with system tools.

Original source
github
License
MIT
Pinned revision
5269f7ea2d6c3a9bfda5ed878b6726cf509121fd

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read github--batch-files at revision 5269f7ea2d6c3a9bfda5ed878b6726cf509121fd, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 10

assets/executable.txt

@echo off REM myTool :: A standalone command-line tool template with argument parsing. :: :: usage: myTool [options] [1] [2] :: [1] = input file path or value :: [2] = output file path (optional) :: :: options: :: /? Show this help message :: -h Show this help message :: --help Show this help message :: -v Show version information :: --verbose Enable verbose output :: :: examples: :: > myTool "C:\data\input.txt" :: > myTool "C:\data\input.txt" "C:\data\output.txt" :: > myTool --verbose "C:\data\input.txt" :: set "_helpLinesMyTool=19"

:: ======================================================================== :: TEMPLATE INSTRUCTIONS :: 1. Find/Replace "myTool" with your executable name (camelCase). :: 2. Find/Replace "MyTool" with your executable name (PascalCase). :: 3. Update the help block above (lines 2-19) for your tool. :: 4. Implement your logic in :_runMyTool. :: 5. Add any new variables to :_removeBatchVariablesMyTool. :: ========================================================================

:: Config variables. set "_versionMyTool=1.0.0" set "_verboseMyTool=0"

:: Define paths. set "_scriptDirMyTool=%~dp0" set "_scriptNameMyTool=%~n0"

:: Parse arguments into variables. set "_parOneMyTool=%~1" set "_checkParOneMyTool=-%_parOneMyTool%-" set "_parTwoMyTool=%~2" set "_checkParTwoMyTool=-%_parTwoMyTool%-" set "_parThreeMyTool=%~3" set "_checkParThreeMyTool=-%_parThreeMyTool%-"

:: ----------------------------------------------------------------------- :: Handle help and version flags. :: ----------------------------------------------------------------------- if "%_parOneMyTool%"=="/?" call :_showHelpMyTool & goto _removeBatchVariablesMyTool if /i "%_parOneMyTool%"=="-h" call :_showHelpMyTool & goto _removeBatchVariablesMyTool if /i "%_parOneMyTool%"=="--help" call :_showHelpMyTool & goto _removeBatchVariablesMyTool if /i "%_parOneMyTool%"=="-v" ( echo %_scriptNameMyTool% version %_versionMyTool% goto _removeBatchVariablesMyTool )

:: ----------------------------------------------------------------------- :: Handle --verbose flag (shift arguments if present). :: ----------------------------------------------------------------------- if /i "%_parOneMyTool%"=="--verbose" ( set "_verboseMyTool=1" set "_parOneMyTool=%~2" set "_checkParOneMyTool=-%~2-" set "_parTwoMyTool=%~3" set "_checkParTwoMyTool=-%~3-" )

:: Create temp directory for intermediate files. call :_makeTempDirMyTool

:: ----------------------------------------------------------------------- :: Validate required input and start execution. :: ----------------------------------------------------------------------- if "%_checkParOneMyTool%"=="--" ( echo ERROR: No input specified. Run "%_scriptNameMyTool% /?" for usage. 1>&2 goto _removeBatchVariablesMyTool )

call :_startMyTool goto _removeBatchVariablesMyTool

:: ======================================================================== :: MAIN LOGIC :: ========================================================================

:_startMyTool if "%_verboseMyTool%"=="1" ( echo [VERBOSE] Input: %_parOneMyTool% echo [VERBOSE] Output: %_parTwoMyTool% )

REM Validate input file exists.
if NOT EXIST "%_parOneMyTool%" (
    echo ERROR: Input file not found: %_parOneMyTool% 1>&2
    goto :eof
)

call :_runMyTool

goto :eof

:_runMyTool REM =================================================================== REM TODO: Replace this section with your tool's logic. REM =================================================================== echo Processing: %_parOneMyTool%

if NOT "%_checkParTwoMyTool%"=="--" (
    echo Output to:  %_parTwoMyTool%
    REM Example: copy input to output.
    REM copy /Y "%_parOneMyTool%" "%_parTwoMyTool%" >nul
)

echo Done.

goto :eof

:: ======================================================================== :: SUPPORT FUNCTIONS :: ========================================================================

:_showHelpMyTool echo: for /f "skip=1 delims=" %%a in ('findstr /n "^" "%~f0"') do ( set "_line=%%a" setlocal EnableDelayedExpansion for /f "delims=:" %%n in ("!_line!") do set "_lineNum=%%n" if !_lineNum! GTR %_helpLinesMyTool% ( endlocal goto :eof ) set "_text=!_line:*:=!" if defined _text ( echo !_text:~4! ) else ( echo: ) endlocal ) goto :eof

:_makeTempDirMyTool set "tmpDirMyTool=%TEMP%%~n0%RANDOM%%RANDOM%" set "_tmpDirCreatedMyTool=0" if NOT EXIST "%_tmpDirMyTool%" ( mkdir "%_tmpDirMyTool%" >nul 2>nul set "_tmpDirCreatedMyTool=1" ) goto :eof

:: ======================================================================== :: CLEANUP — Remove all batch variables. :: ======================================================================== :_removeBatchVariablesMyTool set _helpLinesMyTool= set _versionMyTool= set _verboseMyTool= set _scriptDirMyTool= set _scriptNameMyTool= set _parOneMyTool= set _checkParOneMyTool= set _parTwoMyTool= set _checkParTwoMyTool= set _parThreeMyTool= set _checkParThreeMyTool= REM Append new variables above this line.

if "%_tmpDirCreatedMyTool%"=="1" if EXIST "%_tmpDirMyTool%" rmdir /S /Q "%_tmpDirMyTool%" >nul 2>nul
set _tmpDirMyTool=
set _tmpDirCreatedMyTool=
exit /b