试图在批处理脚本Win8中制作电话簿

时间:2015-04-20 12:01:18

标签: windows shell batch-file cmd

我是批量编写的初学者,我正在尝试制作一个打印所有,添加,删除和搜索phonenumbers的电话注册表,但我无法让它正常工作,而且我是&#39我想知道我哪里出错了。代码在下面,提前谢谢。

echo Print out all content ^<1^> 
echo Add a new number ^<2^> 
echo Delete a number ^<3^> 
echo Search ^<4^> 
echo Exit ^<5^> 
set /p val="Choose between 1-5: " 

GOTO CASE_%val% 
:CASE_1 for /f "tokens=*" %%a in 
(telephoneregister.txt) do 
( echo %%a ) 
GOTO END_SWITCH 
:CASE_2 echo "Number: " set /p p1="Nr" 
echo %p1% >> %output%\telephoneregister.txt 
GOTO END_SWITCH 
:CASE_3 echo "Which number would you like to delete? " 
set /p num="Telephoneregister" 
type telephoneregister.txt | findstr /v %num% >telephoneregister.txt del /s telephoneregister.txt 
type telephoneregister.txt > tele.txt del /s tele1.txt 
GOTO END_SWITCH 
:CASE_4 set /p n1="Number: "
 findstr %n1% telephoneregister.txt 
GOTO END_SWITCH 
:CASE_5 exit 0
 GOTO END_SWITCH 
:END_SWITCH 
pause

1 个答案:

答案 0 :(得分:2)

我在这里得到了这段代码:

@echo off
:menu
cls
echo 1- Print out all content 
echo 2- Add a new number
echo 3- Delete a number
echo 4- Search
echo 5- Exit 
set /p val="Choose between 1-5: " 
if %val%== 1 goto one
if %val%== 2 goto two
if %val%==3 goto three
if %val%== 4 goto four
if %val%== 5 goto five

:one
cls
type telephoneregister.txt
echo.
echo ====================
set /p =ENTER to go back to menu.
goto menu

:two
cls
set /p p1="Number: " 
echo %p1% >> telephoneregister.txt
echo. 
echo ====================
set /p =ENTER to go back to menu.
goto menu

:three
cls
echo Which number would you like to delete?
set /p num="Telephoneregister: " 
type telephoneregister.txt | findstr /v %num% >telephoneregister.txt del /s telephoneregister.txt 
type telephoneregister.txt > tele.txt del /s tele1.txt 
set /p =ENTER to go back to menu.
goto menu

:four
cls
set /p n1="Number: "
findstr /r /c:%n1% telephoneregister.txt
echo.
echo ====================
SET /p =ENTER to go back to menu.
goto menu

:five
exit

它还没有完全完成(选项3它不能正常工作),但你可以看到你的错误,并且可能会在网上搜索解决方案。如果您在上面的代码中有任何问题,请问!祝你好运。