Best practices for Windows Batch scripts (.bat). Covers encoding, path handling, variables, error management, and common pitfalls.
Provides Windows Batch script best practices for encoding, path handling, variables, error management, and common pitfalls. Triggered when creating or editing .bat files to ensure robust, UTF-8 compatible scripts.
/plugin marketplace add theflysurfer/claude-skills-marketplace/plugin install theflysurfer-claude-skills-marketplace@theflysurfer/claude-skills-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
@echo off
chcp 65001 > nul ; UTF-8 pour caractères spéciaux
setlocal enabledelayedexpansion ; Variables dynamiques
@echo off
chcp 65001 > nul
setlocal enabledelayedexpansion
echo ========================================
echo NOM DU SCRIPT - DESCRIPTION
echo ========================================
echo.
set "SCRIPT_DIR=%~dp0" ; Répertoire du script
set "ROOT_DIR=%SCRIPT_DIR%.." ; Répertoire parent
set "TARGET_EXE=%ROOT_DIR%\app.exe" ; Exécutable cible
set "WORK_DIR=%SCRIPT_DIR%" ; Répertoire de travail
if not exist "%TARGET_EXE%" (
echo ERREUR: app.exe non trouve dans %ROOT_DIR%
echo.
pause
exit /b 1
)
; CORRECT - Utiliser %VAR% au lieu de !VAR!
set "RESULT=%ERRORLEVEL%"
if %RESULT% equ 0 (
echo SUCCES
) else (
echo ECHEC - Code: %RESULT%
)
; ÉVITER - !VAR! seulement si nécessaire
if !RESULT! equ 0 (...)
; Tests d'existence
if exist "%FILE%" (echo Fichier trouve)
if not exist "%FILE%" (echo Fichier manquant)
; Tests de variables
if defined VAR (echo Variable definie)
if /i "%CHOICE%"=="y" (echo Oui choisi)
; Tests numériques
if %CODE% equ 0 (echo Code zero)
if %CODE% neq 0 (echo Code non-zero)
:main_test
echo Test en cours...
goto summary
:summary
echo Fin des tests
; Boucle sur fichiers
for %%f in (*.txt) do (
echo Traitement: %%f
)
; Boucle sur liste
for %%i in (test1 test2 test3) do (
echo Test: %%i
)
set /p "CHOICE=Continuer (y/n)? "
if /i not "%CHOICE%"=="y" goto end
choice /c yn /m "Voulez-vous continuer (Y/N)?"
if errorlevel 2 goto no
if errorlevel 1 goto yes
"%EXECUTABLE%" "%SCRIPT%"
set "RESULT=%ERRORLEVEL%"
if %RESULT% equ 0 (
echo SUCCES - Code: %RESULT%
) else (
echo ECHEC - Code: %RESULT%
exit /b %RESULT%
)
; Vérifier exécutable
if not exist "%EXE_PATH%" (
echo ERREUR: Exécutable manquant
pause
exit /b 1
)
; Vérifier script
if not exist "%SCRIPT_PATH%" (
echo ERREUR: Script manquant
goto next_test
)
echo SUCCES: Operation terminee
echo ERREUR: Fichier non trouve
echo ATTENTION: Script non lance automatiquement
echo ========================================
echo RESUME DES TESTS
echo ========================================
pause >nul ; Pause silencieuse
timeout /t 3 >nul ; Attente 3 secondes
; Guillemets pour espaces
set "PATH_WITH_SPACES=%USERPROFILE%\My Documents"
; Validation avant usage
if not defined REQUIRED_VAR (
echo Variable requise manquante
exit /b 1
)
:cleanup
; Nettoyer variables temporaires
set "TEMP_VAR="
set "RESULT1="
set "RESULT2="
echo Nettoyage termine
exit /b 0
@echo off
chcp 65001 > nul
setlocal enabledelayedexpansion
echo ========================================
echo SCRIPT DE TEST AUTOMATISE
echo ========================================
echo.
set "SCRIPT_DIR=%~dp0"
set "ROOT_DIR=%SCRIPT_DIR%.."
set "TARGET_EXE=%ROOT_DIR%\app.exe"
; Validation prérequis
if not exist "%TARGET_EXE%" (
echo ERREUR: app.exe non trouve
pause
exit /b 1
)
; Test 1
echo Test 1: Compilation...
"%TARGET_EXE%" "test1.ahk"
set "RESULT1=%ERRORLEVEL%"
if %RESULT1% equ 0 (
echo SUCCES: Test 1 passe
) else (
echo ECHEC: Test 1 - Code %RESULT1%
)
; Résumé
echo.
echo ========================================
echo RESUME
echo ========================================
if %RESULT1% equ 0 (
echo Test 1: SUCCES
) else (
echo Test 1: ECHEC
)
pause >nul
chcp 65001 pour UTF-8%VAR% à !VAR! sauf cas spéciauxcmd /c pour forcer CMD au lieu de PSThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.