File 在findstr找到文件后打开该文件

File 在findstr找到文件后打开该文件,file,file-io,findstr,File,File Io,Findstr,我正在为我的命令行类编写批处理。这一点很简单。因此,它在大部分情况下运行良好,直到结束。我不知道我是否正确使用了它。在执行findstr命令之后,我有一个if exist来打开,但是即使findstr找到一个文件,它仍然不会打开它 @echo off rem this file is a simple batch file with 4 options. rem option 1 will display the date. rem option 2 display the current d

我正在为我的命令行类编写批处理。这一点很简单。因此,它在大部分情况下运行良好,直到结束。我不知道我是否正确使用了它。在执行
findstr
命令之后,我有一个
if exist
来打开,但是即使
findstr
找到一个文件,它仍然不会打开它

@echo off 
rem this file is a simple batch file with 4 options.
rem option 1 will display the date.
rem option 2 display the current directory you are in
rem open a file in notedpad.

:main
echo 1) display the current date.
echo 2) display the curent directory you are in.
echo 3) open a file in notepad.
echo 4) exit
echo Please enter a option; 1, 2, 3, 4.

set option=
set /p option=

if %option%//==//  GOTO main
if %option%==1 GOTO First
if %option%==2 GOTO Second
if %option%==3 GOTO Third
if %option%==4 GOTO END
if %option%==GEQ 5 
echo You have entered an invalid option.
GOTO main
:First
echo Today is %date%
echo Do you want to go to the main menu or, exit? Enter start, or end.
set /p option2= "Please Enter start, or end."
if %option2%==start GOTO main
if %option2%==end GOTO end
:Second
echo The current directory you are in is %CD%
:Third
echo Please Enter a file with extension; (ie. hello.txt)

set /p filename1=

echo Enter (y/n)
set /p option4=" You typed %filename1%. Is this correct? "

if exist %homedrive%%homepath%\%filename1% (
echo %homedrive%%homepath%\%filename1% FOUND.
start %homedrive%%homepath%\%filename1% 
) else (
if exist %CD%\%filename1% (
echo %CD%\%filename1% FOUND
start %CD%\%filename1%
GOTO restart
) else (
echo %filename1% COULD NOT BE FOUND.
GOTO drive
)
)
:restart
echo Would you like to return to the menu?
echo enter menu, or close.

set /p restart=

if %restart%==menu GOTO main
if %restart%==close (
exit
) else (
echo you have entered an invalid option.
GOTO restart
) 
:drive
echo Enter the drive the file is located on?

set /p drive1=

if exist %drive1% (
echo %drive1% FOUND.
GOTO location
) else (
echo %drive1% NOT FOUND
GOTO drive
) 

:location
%drive1%
cd \
dir /s /b | findstr /i /s "%filename1%"

if exist %filename1% (
start %filename1%
) else (
echo %filename1% NOT FOUND
)
)
:END
pause