Determine Yes/No/All string for current locale

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
dbenham
Expert
Posts: 2451
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

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

#16 Post by dbenham » 29 Oct 2020 17:07

I like it. You might want to include space in the delimiter list if you want the entire word without trailing space.

siberia-man
Posts: 193
Joined: 26 Dec 2013 09:28
Contact:

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

#17 Post by siberia-man » 30 Oct 2020 08:49

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 /)?

isidroco
Posts: 6
Joined: 21 Oct 2020 08:54

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

#18 Post by isidroco » 20 Dec 2020 14:45

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%

Post Reply