본문으로 건너뛰기
Skillpedia
일반 코딩40k · #7090

batch-files

하는 일

이 에이전트는 Windows에서 ‘배치 파일’(.bat 또는 .cmd)이라는 스크립트를 만들고 관리하는 데 도움을 줍니다. 새 스크립트를 작성하고, 기존 스크립트의 오류를 고치고, 컴퓨터의 반복 작업을 자동화할 수 있습니다.

사용하는 경우

  • ✓Windows에서 작업을 자동화하는 스크립트를 만들어야 할 때.
  • ✓.bat 또는 .cmd 스크립트가 기대대로 작동하지 않을 때.
  • ✓명령줄 스크립트를 정리하고 관리하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/batch-files/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/batch-files/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“한 폴더의 모든 .txt 파일을 다른 폴더로 복사하는 .bat 스크립트를 만들어 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 변수 치환부터 명령 실행까지 Windows 명령이 처리되는 방식을 이해합니다. 또한 ‘if’와 ‘for’ 같은 제어 구조를 사용해 스크립트가 판단하고 작업을 반복하도록 만드는 방법도 알고 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Batch Files

A comprehensive skill for creating, editing, debugging, and maintaining Windows batch files (.bat/.cmd) using cmd.exe. Applies to CLI tool development, system administration automation, scheduled tasks, file operations scripting, and PATH-based executable scripts.

When to Use This Skill

  • Creating or editing .bat or .cmd files
  • Automating Windows tasks (file operations, deployments, backups)
  • Building CLI tools intended for a bin/ folder on PATH
  • Writing scheduled task scripts (SCHTASKS, Task Scheduler)
  • Debugging batch script issues (variable expansion, error levels, quoting)
  • Integrating batch scripts with external tools (curl, git, Node.js, Python)
  • Scaffolding new batch-based projects with structured templates

Prerequisites

  • Windows NT-based OS (Windows 7 or later)
  • cmd.exe (built-in)
  • Optional: a bin/ directory on PATH for distributing scripts as commands
  • Optional: PATHEXT configured to include .BAT;.CMD (default on Windows)

Command Interpretation

cmd.exe processes each line through four stages in order:

  1. Variable substitution — %VAR% tokens are replaced with environment variable values. %0–%9 reference batch arguments. %* expands to all arguments.
  2. Quoting and escaping — Caret ^ escapes special characters (& | < > ^). Quotation marks prevent interpretation of enclosed special characters. In batch files, %% yields a literal %.
  3. Syntax parsing — Lines are split into pipelines (|), compound commands (&, &&, ||), and parenthesized groups ( ).
  4. Redirection — > overwrites, >> appends, < reads input, 2> redirects stderr, 2>&1 merges stderr into stdout, >NUL discards output.

Variables

Environment Variables

set _MY_VAR=Hello World
echo %_MY_VAR%
set _MY_VAR=
  • set with no arguments lists all variables
  • set _PREFIX lists variables starting with _PREFIX
  • No spaces around = — set name = val sets variable "name " to " val"

Special Variables

Variable Value
%CD% Current directory
%DATE% System date (locale-dependent)
%TIME% System time HH:MM:SS.mm
%RANDOM% Pseudorandom number 0–32767
%ERRORLEVEL% Exit code of last command
%USERNAME% Current user name
%USERPROFILE% Current user profile path
%TEMP% / %TMP% Temporary file directory
%PATHEXT% Executable extensions list
%COMSPEC% Path to cmd.exe

Scoping with SETLOCAL / ENDLOCAL

setlocal
set _LOCAL_VAR=scoped value
endlocal
REM _LOCAL_VAR is no longer defined here

To return a value from a scoped block:

endlocal & set _RESULT=%_LOCAL_VAR%

Delayed Expansion

Variables inside parenthesized blocks are expanded at parse time. Use delayed expansion for runtime evaluation:

setlocal EnableDelayedExpansion
set _COUNT=0
for /l %%i in (1,1,5) do (
    set /a _COUNT+=1
    echo !_COUNT!
)
endlocal
  • !VAR! expands at execution time (delayed)
  • %VAR% expands at parse time (immediate)

Control Flow

Conditional Execution

if exist "output.txt" echo File found
if not defined _MY_VAR echo Variable not set
if "%_STATUS%"=="ready" (echo Go) else (echo Wait)
if %ERRORLEVEL% neq 0 echo Command failed

Comparison operators: equ, neq, lss, leq, gtr, geq. Use /i for case-insensitive string comparison.

Compound Commands

command1 & command2        & REM Always run both
command1 && command2       & REM Run command2 only if command1 succeeds
command1 || command2       & REM Run command2 only if command1 fails

FOR Loops

REM Iterate over a set of values
for %%i in (alpha beta gamma) do echo %%i

REM Numeric range: start, step, end
for /l %%i in (1,1,10) do echo %%i

REM Files in a directory
for %%f in (*.txt) do echo %%f

REM Recursive file search
for /r %%f in (*.log) do echo %%f

REM Directories only
for /d %%d in (*) do echo %%d

REM Parse command output
for /f "tokens=1,2 delims=:" %%a in ('ipconfig ^| findstr "IPv4"') do echo %%b

REM Parse file lines
for /f "usebackq tokens=*" %%a in ("data.txt") do echo %%a

GOTO and Labels

goto :main_logic
:usage
echo Usage: %~nx0 [options]
exit /b 1

:main_logic
echo Running main logic...
goto :eof

goto :eof exits the current batch or subroutine. Labels start with :.

Command-Line Arguments

Syntax Value
%0 Script name as invoked

…

자주 묻는 질문

‘배치 파일’이란 무엇인가요?

.bat 또는 .cmd 확장자를 가진 간단한 텍스트 파일로, 자동으로 실행되는 Windows 명령의 순서를 담고 있습니다.

이 스크립트를 쓰려면 무언가 설치해야 하나요?

아니요, ‘배치 파일’은 이미 설치되어 있는 Windows 명령 인터프리터(cmd.exe)를 그대로 사용합니다.

스크립트는 어떤 인자를 사용할지 어떻게 아나요?

스크립트를 실행할 때 파일 이름이나 폴더 이름 같은 정보를 전달할 수 있으며, 스크립트는 %1, %2 같은 특수 변수를 통해 이를 사용합니다.

상세 정보

작성자의 원본 설명

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, strin

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7090
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬