batch-file - 批处理文件仅在用户对两个问题都输入"is"时才能正常工作..否则会崩溃

标签 batch-file input crash

今天早些时候我在这里问了一个问题并得到了解决,但现在我遇到了另一个问题..我的批处理文件应该接受目录的用户输入,然后将该目录中的所有文件名称保存到用户指定名称的文本文件。它还具有允许您包含或不包含子目录和隐藏/系统文件的选项。我的问题是,只有当用户决定包含隐藏/系统文件和子目录时,它才能正常工作,否则,它会崩溃。这是代码:

@echo off
:start
set /P DIRECTORY=Type Directory to Search: 
if not exist %DIRECTORY% goto :firstlogin
set /P FILENAME=Type the name for your output file:


:choice
set /P c=Include Sub-Directories?[y/n]?
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "y" goto :somewhere
if /I "%c%" EQU "Yes" goto :somewhere
if /I "%c%" EQU "yes" goto :somewhere
if /I "%c%" EQU "YES" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
if /I "%c%" EQU "n" goto :somewhere_else
if /I "%c%" EQU "No" goto :somewhere_else
if /I "%c%" EQU "no" goto :somewhere_else
if /I "%c%" EQU "NO" goto :somewhere_else
goto :choice


:somewhere
set /P d=Include Hidden and System Files?[y/n]?
if /I "%d%" EQU "Y" goto :d1
if /I "%d%" EQU "y" goto :d1
if /I "%d%" EQU "Yes" goto :d1
if /I "%d%  EQU "yes" goto :d1
if /I "%d%" EQU "YES" goto :d1
if /I "%d%" EQU "N" goto :d2
if /I "%d%" EQU "n" goto :d2
if /I "%d%" EQU "No" goto :d2
if /I "%d%" EQU "no" goto :d2
if /I "%d%" EQU "NO" goto :d2
goto :somewhere

:d1
echo The Program Will Exit When Operations are Completed....
Pause
echo Working Please Wait... 
Pause
dir /a /s /b /o  "%DIRECTORY%" > C:\Users\Zack\Desktop\%FILENAME%.txt
exit


:d2
echo The Program Will Exit When Operations are Completed....
Pause
echo Working Please Wait... 
Pause
dir /s /b /o  "%DIRECTORY%" > C:\Users\Zack\Desktop\%FILENAME%.txt
exit



:somewhere_else
set /P e=Include Hidden and System Files?[y/n]?
if /I "%e%" EQU "Y" goto :e1
if /I "%e%" EQU "y" goto :e1
if /I "%e%" EQU "Yes" goto :e1
if /I "%e%" EQU "yes" goto :e1
if /I "%e%" EQU "YES" goto :e1
if /I "%e%" EQU "N" goto :e2
if /I "%e%" EQU "n" goto :e2
if /I "%e%" EQU "No" goto :e2
if /I "%e%" EQU "no" goto :e2
if /I "%e%" EQU "NO" goto :e2
goto :somewhere_else


e1:
echo The Program Will Exit When Operations are Completed....
Pause
echo Working Please Wait... 
Pause
dir /a /b /o  "%DIRECTORY%" > C:\Users\Zack\Desktop\%FILENAME%.txt
exit


e2:
echo The Program Will Exit When Operations are Completed....
Pause
echo Working Please Wait... 
Pause
dir /b /o "%DIRECTORY%" > C:\Users\Zack\Desktop\%FILENAME%.txt
exit


:firstlogin
echo Directory does not exist!
Pause
goto :start


:done
SET stg=
SET /P stg=Start again?[y/n]? 
cls
IF %stg% == Y goto :START
IF %stg% == y goto :START
IF %stg% == yes goto :START
IF %stg% == Yes goto :START
IF %stg% == YES goto :START

最佳答案

这是一个简单的错字:

e1: 
echo The Program Will Exit When Operations are Completed.... 

应该是:

:e1
echo The Program Will Exit When Operations are Completed.... 

e2:相同,应为:e2

注意错误消息...

编辑:

关于您的评论,请检查:

:somewhere 
set /P d=Include Hidden and System Files?[y/n]? 
if /I "%d%" EQU "Y" goto :d1 
if /I "%d%" EQU "y" goto :d1 
if /I "%d%" EQU "Yes" goto :d1 
if /I "%d%  EQU "yes" goto :d1 

最后一行在 "%d 之后缺少 "

调试这样的事情非常容易。只需在开头将 echo off 更改为 echo on,您就会看到最后执行的行和错误消息。

关于batch-file - 批处理文件仅在用户对两个问题都输入"is"时才能正常工作..否则会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2339659/

相关文章:

c++ - 正确数据类型的输入验证?

javascript - Cmd + 文本选择不起作用,只允许在文本字段输入数字

python - 在python中任意时间捕获用户输入

ruby-on-rails - Heroku 应用总是崩溃

ios - 为什么我的程序总是说 "unrecognised selector sent to instance"?

ios - 我的应用程序经常但随机地在应用程序加载时使整个手机崩溃

windows - windows批处理中call和cmd/c的区别

batch-file - 将 zip 内容解压到与 zip 文件同名的目录中,保留目录结构

windows - 如何从命令行检查文件的大小

batch-file - 管道之后 "set -P"为什么不起作用?