Windows 7 batch files: How to check if parameter has been passed to batch file

if %1.==. dir will break if the parameter includes various symbols like ", <, etc

if "%1"=="" will break if the parameter includes a quote (").

Use if "%~1"=="" instead:

if "%~1"=="" (
    echo No parameters have been provided.
) else (
    echo Parameters: %*
)

This should work on all versions of Windows and DOS.

Unit Test:

C:\>test
No parameters have been provided.

C:\>test "Lots of symbols ~@#$%^&*()_+<>?./`~!, but works"
Parameters: "Lots of symbols ~@#$%^&*()_+<>?./`~!, but works"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)