本文へスキップ
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がスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/github/awesome-copilot/blob/main/skills/batch-files/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に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

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル