batch-files

Write, debug, and maintain Windows batch files using cmd.exe syntax and patterns.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill batch-files
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: batch-files
Source: https://github.com/github/awesome-copilot/tree/main/skills/batch-files
Command: npx skills add https://github.com/github/awesome-copilot --skill batch-files

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

Writing correct Windows batch files is error-prone due to cmd.exe quirks like parse-time variable expansion, quoting pitfalls, and inconsistent ERRORLEVEL behavior. This Skill provides expert guidance for creating, debugging, and maintaining .bat and .cmd scripts without falling into these traps.

Core Features & Use Cases

  • Complete cmd.exe Reference: Covers command interpretation stages, environment variables, delayed expansion, control flow, FOR loops, string processing, arithmetic, and error handling conventions.
  • Production Templates: Ships starter templates for standalone CLI tools with argument parsing, reusable function libraries, and scheduled task automation scripts with logging.
  • Deep Reference Material: Includes an A-Z Windows command reference, batch scripting techniques (date math, string length, input validation), and guides for Cygwin, MSYS2, and WSL integration.
  • Use Case: When asked to automate a Windows backup task, the Skill produces a robust script with argument validation, stderr error reporting, ROBOCOPY-based file operations, and a scheduled task registration via SCHTASKS.

Quick Start

Ask the AI to create a batch file that automates your Windows task, such as writing a .bat script that backs up a folder and logs the results.

Frequently Asked Questions about batch-files

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Windows batch file with argument parsing?

Use a GOTO loop that checks %~1 against flag names like --help or --output, calling SHIFT after each consumed argument. The Skill provides a standard template with a :parse_args label, usage output, and validation of required parameters before processing.

Why is my variable not updating inside a FOR loop in a batch file?

Variables with %VAR% syntax are expanded at parse time, before the loop runs. Enable delayed expansion with setlocal EnableDelayedExpansion and use !VAR! instead so values are evaluated at execution time inside parenthesized blocks.

What is the difference between .bat and .cmd files?

Both run under cmd.exe, but .CMD files reset ERRORLEVEL after every internal command while .BAT files only set it on error. The .CMD extension is preferred for predictable exit-code behavior in automation.

How do I schedule a batch script to run automatically on Windows?

Use the SCHTASKS command to register the script with Task Scheduler, specifying triggers like daily time or system startup. The Skill's task template includes logging, dry-run mode, and directory restoration suitable for scheduled execution.

When should I use PowerShell instead of a batch file?

Batch files suit fast startup, simple file operations, PATH-based CLI tools, and Task Scheduler integration. PowerShell or WSL is better for complex data processing, REST API calls, or object-oriented scripting beyond cmd.exe capabilities.

How do I prevent code injection in batch file user input?

Always quote variables like "%_USER_INPUT%" and use delayed expansion (!VAR!) for values from SET /P, since it resolves after command splitting where injection occurs. Reject input containing doublequotes, ampersands, or pipes with FINDSTR validation.