Discussion forum for all Windows batch related topics.
I like it. You might want to include space in the delimiter list if you want the entire word without trailing space.
Trailing spaces are already trimmed in the separate section of the script. I didn't include the space in the delimiter list because it would be too hard to parse the string. Even more, I am not sure that the existing [(/)] delimiters are 100% reliable. What if they are applicable in the user name (except /)?
Thanks Siberia-Man, your code doesn't work if TEMP folder includes (). Here's a slighly simplified version, based also on jfl, skips an "if", doesn't need delayed expansion and allows easy testing. Won't work if TEMP folder has # on it (one could choose another unused valid character on dummy "yesnoall#.tmp" file). I think this could be final solution:
Code: Select all
@echo off set PromptLine= copy /y nul "%TEMP%\yesnoall#.tmp" >nul for /f "tokens=2* delims=#" %%A in ( '^<nul copy /-y nul "%TEMP%\yesnoall#.tmp"' ) do set PromptLine=%%A del "%TEMP%\yesnoall#.tmp" set PromptLine=%PromptLine: =%& rem delete spaces (for russian) for /f "tokens=2-7 delims=[(/)]" %%A in ( "%PromptLine%" ) do if "%%~E" == "" ( set ans_yes=%%A& set ans_no=%%B& set ans_all=%%C ) else ( set ans_yes=%%A& set ans_no=%%C& set ans_all=%%E ) set ans_y=%ans_yes:~0,1%& set ans_n=%ans_no:~0,1%& set ans_a=%ans_all:~0,1% echo %ans_yes%, %ans_no%, %ans_all% echo %ans_y%, %ans_n%, %ans_a%