コマンド ライン クラスのバッチを作成しています。この時点ではかなり単純です。そのため、最後に到達するまで、ほとんどの部分でうまく実行されます。使い方が正しいのかわかりません。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