bat

bat文件语法检查脚本

Posted by Darren Blog on September 10, 2024

检查bat文件中是否有语法错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@echo off
setlocal enabledelayedexpansion
set "DIRECTORY=\path\"
 
for /r "%DIRECTORY%" %%f in (*.bat) do (
    echo Checking syntax of %%~nxf
    cmd /c ""%%~f" >nul 2>nul" && (
        echo %%~nxf syntax is correct.
    ) || (
        echo Error: %%~nxf has syntax errors.
        cmd /c ""%%~f"">nul 2>syntax_errors.txt"
        type syntax_errors.txt
        del syntax_errors.txt
    )
)
 
endlocal