I'm in need of assistance figuring this out a way to do some basic user input normalization. The batch prompts for a path and expects something like
- software\adobe
image\WinXP
etc
However I'm trying to build some basic 'intelligence' to remove strings that start with a backslash and double quotes. Otherwise paths like this will fail:
- \software\adobe
"image\Windows 7"
"\software\Nero Burning"
etc
Detecting & clearing the backslash was no problem..
Code: Select all
if "!arg:~0,1!" EQU "\" (
echo. & echo. WARNING: Path starts with a slash and it should not
echo. User Input: !arg!
set arg=!arg:~1!
)
But I can't figure out how to detect whether or not the string starts with a double quote.
Code: Select all
if "!arg:~0,1!" EQU """ (
echo bad double quotes
)
if "!arg:~0,1!" EQU "\"" (
echo bad double quotes
)
if "^!arg:~0,1!" EQU "\"" (
echo bad double quotes
)
if "^!arg:~0,1!" EQU "^"" (
echo bad double quotes
)
And several other variants with/without brackets and carrots etc.
Presumably once I figure that out I can use this technique (thanks to DosTips for that) to remove the first & last characters which should be quotes.
Code: Select all
set arg=%arg:~1,-1%
Its not urgent, its not serious. I'm the only one that uses this script, that I know of, but I know at some point once word gets out others will want to use this as well.
Many thanks