Page 2 of 2

Re: Determine Yes/No/All string for current locale

Posted: 29 Oct 2020 17:07
by dbenham
I like it. You might want to include space in the delimiter list if you want the entire word without trailing space.

Re: Determine Yes/No/All string for current locale

Posted: 30 Oct 2020 08:49
by siberia-man
dbenham wrote:
29 Oct 2020 17:07
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 /)?

Re: Determine Yes/No/All string for current locale

Posted: 20 Dec 2020 14:45
by isidroco
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%