|
Answer» Is it POSSIBLE to check for a double quote at the END of a string?
Reason is, I've created a batch file where users drag and DROP a folder onto the batch file and it uses that as a parameter.
If the folder has a space it encloses it in double quotes, I can strip them off with the SET COMMAND...but if there is no space then it doesn't enclose it in quotes.
Code: [Select]set StartFolder=%1 if '%StartFolder%==' goto NoFolder set tmpstr=%StartFolder:~-1%
rem *** If last char is double quote, strip them off - '" = Single the double quote*** if '%tmpstr% == '" set StartFolder=%StartFolder:~1,-1%
set tmpstr=%StartFolder:~-1% rem *** If last char is not backslash, ADD one *** if '%tmpstr% NEQ '\ set StartFolder=%StartFolder%\
How can I check if the parameter has quotes?Solved it by adding a ^ before the double quote...
Code: [Select]set StartFolder=%1 if '%StartFolder%==' goto NoFolder set tmpstr=%StartFolder:~-1%
rem *** If last char is double quote, strip them off - '" = Single the double quote*** if '^%tmpstr% == '^" set StartFolder=%StartFolder:~1,-1%
set tmpstr=%StartFolder:~-1% rem *** If last char is not backslash, add one *** if '%tmpstr% NEQ '\ set StartFolder=%StartFolder%\ You do know that the tilde variable modifier strips off any surrounding quotes from parameter strings?
If %1 is a passed parameter string, then %~1 is that same string but without any surrounding double quotes. (If no quotes are present then %1 and %~1 are identical)
For full details of variable modifiers see the FOR documentation e.g. by typing FOR /? at the prompt.
|