Reputation: 99
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
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