我不知道我的批处理文件有什么问题

时间:2022-09-20 18:57:59

Help! I am making a batch file that you can make a list of people. Then when someone arrives you can type in their name and it will check if they're on the list. When the batch file checks if the person is on the list it does not work(I am using no capital letters and I am spelling it right) I need to figure out what is wrong with my batch file that is not working. So the main problem is that when it checks for the person on the list it does not find it. Sorry, im not exactly sure how to phrase this. :) Here is the code for my program.

救命!我正在创建一个批处理文件,您可以列出人员列表。然后,当有人到达时,您可以输入他们的姓名,并检查他们是否在列表中。当批处理文件检查该人是否在列表中时它不起作用(我没有使用大写字母,我拼写正确)我需要弄清楚我的批处理文件有什么问题。所以主要的问题是,当它检查列表中的人时,它找不到它。对不起,我不确定如何用这句话来表达。 :)这是我的程序的代码。

@echo off
title Event Starter
echo Event Starter
set /p Eventname=Event Name: 
cls
goto :Participants

:Participants
title Name Of Participants
set /p Name1=Name: 
cls
set /p Name2=Name: 
cls
set /p Name3=Name: 
cls
set /p Name4=Name: 
cls
set /p Name5=Name: 
cls
set /p Name6=Name: 
cls
set /p Name7=Name: 
cls
set /p Name8=Name: 
cls
pause
goto :checker

:checker
title Enter Person's Name
echo Enter Who Arrived To Check The Database
echo.
echo.
echo.
set /p check1=
goto :database

:database
title Checking Database For The Given Person
echo Checking Database For The Given Person
cls
echo 5 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 20 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 35 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 50 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 70 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 85 %
ping 1.1.1.1 -n 1 -w 5000 > nul
cls
echo 100 %
ping 1.1.1.1 -n 1 -w 5000 > nul
if %check1%==%Name1% goto :valid
if %check1%==%Name2% goto :valid
if %check1%==%Name3% goto :valid
if %check1%==%Name4% goto :valid
if %check1%==%Name5% goto :valid
if %check1%==%Name6% goto :valid
if %check1%==%Name7% goto :valid
if %check1%==%Name8% goto :valid
goto :invalid

:valid
title %check% Is On The List!
echo %check% Is On The List!
ping 1.1.1.1 -n 1 -w 5000 > nul
ping 1.1.1.1 -n 1 -w 5000 > nul
pause
goto :checker

:invalid
title %check% Is Not On The List!
echo %check% is Not On The List!
echo This Is Case-Sensative
ping 1.1.1.1 -n 1 -w 5000 > nul
ping 1.1.1.1 -n 1 -w 5000 > nul
goto :checker

3 个解决方案

#1


1  

To be honest, there is a lot of unnecessary lines there, so instead of pinpointing the error I have rewritten your script into a much cleaner version, which should hopefully solve the problems you were having as well! :)

说实话,那里有很多不必要的线,所以我没有找到错误,而是将脚本重写为更清晰的版本,这应该有希望解决你遇到的问题! :)

@echo off
title Event Starter
setlocal enabledelayedexpansion
echo Event Starter
set /p Eventname=Event Name: 
cls
title Name Of Participants
for /l %%a in (1,1,8) do (
set /p Name[%%a]=Name: 
cls
)

:checker
title Enter Person's Name
echo Enter Who Arrived To Check The Database
echo.
echo.
echo.
set /p check1=

title Checking Database For The Given Person
echo Checking Database For The Given Person
cls
for %%b in (5,20,35,50,70,85,100) do (
echo %percent%%
ping 1.1.1.1 -n 6 > nul
cls
)
for /l %%a in (1,1,8) do (
if !check1!==!Name[%%a]! goto :valid
)
goto :invalid

:valid
title %check% Is On The List!
echo %check% Is On The List!
ping 1.1.1.1 -n 1 -w 10000 > nul
goto :checker

:invalid
title %check% Is Not On The List!
echo %check% is Not On The List!
echo This Is Case-Sensative
ping 1.1.1.1 -n 1 -w 10000 > nul
goto :checker

#2


1  

--EDIT-- Fixed the code. It should work now.

--EDIT--修正了代码。它现在应该工作。

setlocal enabledelayedexpansion

:a
    cls
    set/p name=Name: 
    for /f "delims=" %%i in (File_path) do (
       set name2=%%i
       if /i !name! equ !name2! goto b
       )
    cls
    echo They're not on the list...
    pause
    goto a
:b
    cls
    echo They're on the list...
    pause
    goto a

The script goes through the file checking if the user-defined name (name) is within it. If it is then it sends it to :b which reports back to you saying that they were on the list. You could modify this into a function by replacing the goto command with exit /b 2 for true (they were on the list) and exit /b 3 for false (they weren't).

如果用户定义的名称(名称)在其中,脚本将检查文件。如果是,那么它会将其发送给:b,它向您报告说它们在列表中。您可以通过将exit / b 2替换为goto命令(它们在列表中)并将/ b 3替换为false(它们不是)来将其修改为函数。

The names should each be on a separate line, demonstrated below. Capitalization doesn't matter because of the /i switch on the if command.

这些名称应各自独立,如下所示。由于/ i启用了if命令,大小写无关紧要。

Mark Finch
Julie Fernz
Tom Riddle...

#3


0  

I am not familiar with the syntax, but there is a difference between the way you input the initial names (e.g. set /p Name1=Name: ) and how you input the name to check (set /p check1= ). Is that significant?

我不熟悉语法,但输入初始名称的方式(例如set / p Name1 = Name :)和输入要检查的名称(set / p check1 =)之间存在差异。这有意义吗?

#1


1  

To be honest, there is a lot of unnecessary lines there, so instead of pinpointing the error I have rewritten your script into a much cleaner version, which should hopefully solve the problems you were having as well! :)

说实话,那里有很多不必要的线,所以我没有找到错误,而是将脚本重写为更清晰的版本,这应该有希望解决你遇到的问题! :)

@echo off
title Event Starter
setlocal enabledelayedexpansion
echo Event Starter
set /p Eventname=Event Name: 
cls
title Name Of Participants
for /l %%a in (1,1,8) do (
set /p Name[%%a]=Name: 
cls
)

:checker
title Enter Person's Name
echo Enter Who Arrived To Check The Database
echo.
echo.
echo.
set /p check1=

title Checking Database For The Given Person
echo Checking Database For The Given Person
cls
for %%b in (5,20,35,50,70,85,100) do (
echo %percent%%
ping 1.1.1.1 -n 6 > nul
cls
)
for /l %%a in (1,1,8) do (
if !check1!==!Name[%%a]! goto :valid
)
goto :invalid

:valid
title %check% Is On The List!
echo %check% Is On The List!
ping 1.1.1.1 -n 1 -w 10000 > nul
goto :checker

:invalid
title %check% Is Not On The List!
echo %check% is Not On The List!
echo This Is Case-Sensative
ping 1.1.1.1 -n 1 -w 10000 > nul
goto :checker

#2


1  

--EDIT-- Fixed the code. It should work now.

--EDIT--修正了代码。它现在应该工作。

setlocal enabledelayedexpansion

:a
    cls
    set/p name=Name: 
    for /f "delims=" %%i in (File_path) do (
       set name2=%%i
       if /i !name! equ !name2! goto b
       )
    cls
    echo They're not on the list...
    pause
    goto a
:b
    cls
    echo They're on the list...
    pause
    goto a

The script goes through the file checking if the user-defined name (name) is within it. If it is then it sends it to :b which reports back to you saying that they were on the list. You could modify this into a function by replacing the goto command with exit /b 2 for true (they were on the list) and exit /b 3 for false (they weren't).

如果用户定义的名称(名称)在其中,脚本将检查文件。如果是,那么它会将其发送给:b,它向您报告说它们在列表中。您可以通过将exit / b 2替换为goto命令(它们在列表中)并将/ b 3替换为false(它们不是)来将其修改为函数。

The names should each be on a separate line, demonstrated below. Capitalization doesn't matter because of the /i switch on the if command.

这些名称应各自独立,如下所示。由于/ i启用了if命令,大小写无关紧要。

Mark Finch
Julie Fernz
Tom Riddle...

#3


0  

I am not familiar with the syntax, but there is a difference between the way you input the initial names (e.g. set /p Name1=Name: ) and how you input the name to check (set /p check1= ). Is that significant?

我不熟悉语法,但输入初始名称的方式(例如set / p Name1 = Name :)和输入要检查的名称(set / p check1 =)之间存在差异。这有意义吗?