JosephFTaylor
JosephFTaylor

Reputation: 99

Checking for specific character in a batch file

I want to check a string in a batch file to make sure it doesn't include any of the following characters: /:*?"<>|

I don't know whether it would be easier to check to see if it contains valid characters, as the batch file might fail with there being the above characters in the code.

Upvotes: 1

Views: 2172

Answers (1)

foxidrive
foxidrive

Reputation: 41287

This is one way:

double quotes are difficult to handle in batch and I didn't add it.
If a double quotes exists in the string variable then this can fail too.

@echo off
set "string=1234abcd"
for /f "delims=/:*?<>|" %%a in ("%string%") do if "%%a"=="%string%" echo characters were not found
pause

Upvotes: 2

Related Questions