Batch file 正在尝试编写一个批处理文件,该批处理文件根据16种方式的选择将16个不同单词中的一个写入文件

Batch file 正在尝试编写一个批处理文件,该批处理文件根据16种方式的选择将16个不同单词中的一个写入文件,batch-file,Batch File,这是我的可怕代码。 你可以看出,我对这件事很陌生。 它本应使在旧游戏中记录基于图片的密码更容易,并具有可定制的代码,但它占用了太多的空间 @echo off SET code1=dog SET code2=cat SET code3=hamster SET code4=chicken SET code5=cow SET code6=horse SET code7=lizard SET code8=snake

这是我的可怕代码。 你可以看出,我对这件事很陌生。 它本应使在旧游戏中记录基于图片的密码更容易,并具有可定制的代码,但它占用了太多的空间

@echo off
SET code1=dog        
SET code2=cat        
SET code3=hamster    
SET code4=chicken    
SET code5=cow        
SET code6=horse      
SET code7=lizard     
SET code8=snake      
SET code9=frog       
SET code10=llama      
SET code11=sheep      
SET code12=rabbit     
SET code13=chinchilla 
SET code14=monkey     
SET code15=human      
SET code16=alien      
:CODE
SET /a n+=1
ECHO 1:%code1%2:%code2%3:%code3%4:%code4%5:%code5%6:%code6%7:%code7%8:%code8%
ECHO Q:%code9%W:%code10%E:%code11%R:%code12%T:%code13%Y:%code14%U:%code15%I:%code16%
CHOICE /c 12345678QWERTYUI /n
set thing=%errorlevel%
if %thing%==1 echo %code1%>passwords.txt
if %thing%==2 echo %code2%>passwords.txt
if %thing%==3 echo %code3%>passwords.txt
if %thing%==4 echo %code4%>passwords.txt
if %thing%==5 echo %code5%>passwords.txt
if %thing%==6 echo %code6%>passwords.txt
if %thing%==7 echo %code7%>passwords.txt
if %thing%==8 echo %code8%>passwords.txt
if %thing%==9 echo %code9%>passwords.txt
if %thing%==10 echo %code10%>passwords.txt
if %thing%==11 echo %code11%>passwords.txt
if %thing%==12 echo %code12%>passwords.txt
if %thing%==13 echo %code13%>passwords.txt
if %thing%==14 echo %code14%>passwords.txt
if %thing%==15 echo %code15%>passwords.txt
if %thing%==16 echo %code16%>passwords.txt
if n lss 8 goto CODE
rem change this number for length of password
echo done
它应该做的是将8个单词输出到文本文件的一行,即按“1q2w3e4r”将“狗蛙猫骆驼仓鼠羊鸡兔”输出到文本文件。

以下是:

@echo off & Setlocal Enabledelayedexpansion

:: Set the codes
Set "Codes=dog cat hamster chicken cow horse lizard snake frog llama sheep rabbit chinchilla monkey human alien"
:: Set the Choice Options
Set "Opts=1 2 3 4 5 6 7 8 Q W E R T Y U I"

:: Set up the Code Variables
For %%C in (%Codes%) Do (
    Set /A "CodeIndex+=1"
    Set "Code!CodeIndex!=%%C"
)

:: Set up the Choice Letter Variables
For %%O in (%Opts%) Do (
    Set /A "OptIndex+=1"
    Set "Opt!OptIndex!=%%O"
)

:Menu
:: Display the menu
For /L %%N in (1, 1, 8) Do (<nul Set /P "=!Opt%%N!:!Code%%N! ")
Echo+
For /L %%N in (9, 1, 16) Do (<nul Set /P "=!Opt%%N!:!Code%%N! ")
Echo+

CHOICE /C "%Opts: =%" /n

:: Return
:: If %ERRORLEVEL% lss 9 (goto :MENU)

:: Write the selected code
Echo !Code%ERRORLEVEL%!>".\Passwords.txt"

:END
Exit /B 0
@echo off&Setlocal Enabledelayedexpansion
::设置代码
设置“代码=狗、猫、仓鼠、鸡、牛、马、蜥蜴、蛇、蛙、美洲驼、绵羊、兔子、栗鼠、猴子、人类、外星人”
::设置选项
设置“选项=1 2 3 4 5 6 7 8 Q W E R T Y U I”
::设置代码变量
对于%%C in(%code%)执行(
设置/A“代码索引+=1”
设置“代码!代码索引!=%%C”
)
::设置选项字母变量
对于(%Opts%)中的%%O,请执行以下操作(
设置/A“OptIndex+=1”
设置“Opt!OptIndex!=%%O”
)
:菜单
::显示菜单
对于(1,1,8)Do(中的/L%%N,如下所示:

@echo off & Setlocal Enabledelayedexpansion

:: Set the codes
Set "Codes=dog cat hamster chicken cow horse lizard snake frog llama sheep rabbit chinchilla monkey human alien"
:: Set the Choice Options
Set "Opts=1 2 3 4 5 6 7 8 Q W E R T Y U I"

:: Set up the Code Variables
For %%C in (%Codes%) Do (
    Set /A "CodeIndex+=1"
    Set "Code!CodeIndex!=%%C"
)

:: Set up the Choice Letter Variables
For %%O in (%Opts%) Do (
    Set /A "OptIndex+=1"
    Set "Opt!OptIndex!=%%O"
)

:Menu
:: Display the menu
For /L %%N in (1, 1, 8) Do (<nul Set /P "=!Opt%%N!:!Code%%N! ")
Echo+
For /L %%N in (9, 1, 16) Do (<nul Set /P "=!Opt%%N!:!Code%%N! ")
Echo+

CHOICE /C "%Opts: =%" /n

:: Return
:: If %ERRORLEVEL% lss 9 (goto :MENU)

:: Write the selected code
Echo !Code%ERRORLEVEL%!>".\Passwords.txt"

:END
Exit /B 0
@echo off&Setlocal Enabledelayedexpansion
::设置代码
设置“代码=狗、猫、仓鼠、鸡、牛、马、蜥蜴、蛇、蛙、美洲驼、绵羊、兔子、栗鼠、猴子、人类、外星人”
::设置选项
设置“选项=1 2 3 4 5 6 7 8 Q W E R T Y U I”
::设置代码变量
对于%%C in(%code%)执行(
设置/A“代码索引+=1”
设置“代码!代码索引!=%%C”
)
::设置选项字母变量
对于(%Opts%)中的%%O,请执行以下操作(
设置/A“OptIndex+=1”
设置“Opt!OptIndex!=%%O”
)
:菜单
::显示菜单

对于(1,1,8)Do(中的/L%%N,您的计数循环已中断,我不知道它应该如何工作,因此我将其完全删除。 我还删除了对密码文件的重定向,以便于查看正在发生的事情——它可以很容易地添加回来

下面的代码很容易应用于代码单词列表的加减。该列表只需在一个位置更新。我添加了几个条目以显示它有多容易,并且显示它不需要是8的倍数

我假设您希望去掉代码词的尾随空格——它们只是为了适当的菜单间距

@echo off
setlocal enableDelayedExpansion
set "n=0"
set "keys="
for /f "delims==" %%A in ('set $prompt 2^>nul') do set "%%A="
for %%A in (
  "1:dog        "
  "2:cat        "
  "3:hamster    "
  "4:chicken    "
  "5:cow        "
  "6:horse      "
  "7:lizard     "
  "8:snake      "
  "Q:frog       "
  "W:llama      "
  "E:sheep      "
  "R:rabbit     "
  "T:chinchilla "
  "Y:monkey     "
  "U:human      "
  "I:alien      "
  "A:godzilla   "
  "S:orc        "
  "D:medussa    "
) do (
  set /a "p=n/8,n+=1"
  for %%P in (!p!) do set "$prompt%%P=!$prompt%%P!%%~A"
  for /f "tokens=1,2 delims=: " %%B in (%%A) do (
    set "keys=!keys!%%B"
    set "code!n!=%%C"
  )
)
for /f "delims== tokens=1,2" %%A in ('set $prompt') do echo %%B
choice /c !keys! /n
for %%N in (%errorlevel%) do echo !code%%N!

你的计数循环被打破了,我不知道它应该如何工作,所以我把它完全移除了。 我还删除了对密码文件的重定向,以便于查看正在发生的事情——它可以很容易地添加回来

下面的代码很容易应用于代码单词列表的加减。该列表只需在一个位置更新。我添加了几个条目以显示它有多容易,并且显示它不需要是8的倍数

我假设您希望去掉代码词的尾随空格——它们只是为了适当的菜单间距

@echo off
setlocal enableDelayedExpansion
set "n=0"
set "keys="
for /f "delims==" %%A in ('set $prompt 2^>nul') do set "%%A="
for %%A in (
  "1:dog        "
  "2:cat        "
  "3:hamster    "
  "4:chicken    "
  "5:cow        "
  "6:horse      "
  "7:lizard     "
  "8:snake      "
  "Q:frog       "
  "W:llama      "
  "E:sheep      "
  "R:rabbit     "
  "T:chinchilla "
  "Y:monkey     "
  "U:human      "
  "I:alien      "
  "A:godzilla   "
  "S:orc        "
  "D:medussa    "
) do (
  set /a "p=n/8,n+=1"
  for %%P in (!p!) do set "$prompt%%P=!$prompt%%P!%%~A"
  for /f "tokens=1,2 delims=: " %%B in (%%A) do (
    set "keys=!keys!%%B"
    set "code!n!=%%C"
  )
)
for /f "delims== tokens=1,2" %%A in ('set $prompt') do echo %%B
choice /c !keys! /n
for %%N in (%errorlevel%) do echo !code%%N!

你有具体问题吗?如果有,请帮助我们关注你需要帮助的内容。我想他想知道如何简化代码。你有具体问题吗?如果有,请帮助我们关注你需要帮助的内容。我想他想知道如何简化代码。