このバッチスクリプトを動作させるのに数日を費やしましたが、正しく動作していないようです。それは私に変数を設定するように促した後、それを設定した後に必要なことをやっているようです。コマンドを正しく実行するとバッチスクリプトが使用されません
たとえば、存在していないと思われる場合はn
と入力してください。そうすればスクリプトを終了するだけです。しかし、私がそれを開いて前と同じことを言い、n
と入力すると、ちょうど私がy
とタイプしたかのように、DeleteCalcにジャンプするかもしれません。私はおそらく間違って何をしていることができ
@echo off
:Begin
color fc
title My script
cls
if not exist "C:\calc.exe" (
echo calc.exe doesn't seem to exist. Attempt deletion anyway? ^(Y/N^)
set "calcnotexist="
set /p "calcnotexist="
::This command checks to see if the user inputs a quotation mark. If they do, it echos that quotes cannot be inputted.
setlocal EnableDelayedExpansion
if not !calcnotexist!==!calcnotexist:^"=! set "calcnotexist="
endlocal & if "%calcnotexist%"=="" (
echo ERROR - Quotes cannot be entered.
pause
goto Begin
)
if /i "%calcnotexist%"=="Y" (
echo.
goto DeleteCalc
)
if /i "%calcnotexist%"=="Yes" (
echo.
goto DeleteCalc
)
if /i "%calcnotexist%"=="N" goto End
if /i "%calcnotexist%"=="No" goto End
echo ERROR - Unrecognized input
pause
goto Begin
)
:calcDoesExist
title My script
cls
echo calc.exe found. Delete? ^(Y/N^)
set "calcexist="
set /p "calcexist="
::This command checks to see if the user inputs a quotation mark. If they do, it echos that quotes cannot be inputted.
setlocal enabledelayedexpansion
if not !calcexist!==!calcexist:^"=! set "calcexist="
endlocal & if "%calcexist%"=="" (
echo ERROR - Quotes cannot be entered.
pause
goto calcDoesExist
)
if /i "%calcexist%"=="Y" goto DeleteCalc
if /i "%calcexist%"=="Yes" goto DeleteCalc
if /i "%calcexist%"=="N" goto End
if /i "%calcexist%"=="No" goto End
echo ERROR - Unrecognized input
pause
goto calcDoesExist
:DeleteCalc
cls
echo Deleting...
if not exist C:\calc.exe goto Success
del /f /q C:\calc.exe >nul 2>nul
if not exist C:\calc.exe goto Success
echo Fail!
echo.
echo calc.exe could not be deleted.
echo.
pause
goto End
:Success
echo Deleted!
echo.
echo calc.exe successfully deleted.
echo.
pause
goto End
:End
exit /b
:
は、ここに私のスクリプトですか?
ありがとう
P.S.私は、CMDを開いてそこでバッチスクリプトを複数回実行することでこれをテストしました。 (でも、それをダブルクリックするだけではうまくいきません)
私は申し訳ありませんが、私はそれを記述するためにどのように他を知りません。英語は母国語ではありません。 – ditheredtransparency
最初のIFブロックを入力すると、すべての変数を遅延拡張で参照する必要があります。 – Squashman
@abelenky:これはどうですか?:_ "[現在のディレクトリは存在しません](http://stackoverflow.com/questions/41310409/current-directory-does-not-exist-batch-files)" _ – Aacini