gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:49:06 25 4
gpt4 key购买 nike

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

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com