我无法弄清楚这一点,我真的不知道如何制定这个问题,我希望这已经足够了 我正在研究这个实验。 当我故意插入无效目录时,我收到消息“系统无法找到指定的路径。”
@echo off
set /a test=0
title Color changer
if exist "Settings/files.bat" (
call Settings/files.bat
) else (
mkdir Settings
echo set savloc=%cd%>Settings\files.bat
call Settings\files.bat
)
if exist "%savloc%\color.bat" (
call "%savloc%\color.bat"
) else (
color 0f
)
set menu=2
goto menu
:menu
cls
echo color : change color
echo cd : change direction
set /p menu=
if "%menu%" == "color" goto setcolor
if "%menu%" == "cd" goto changedir
else goto menu
:changedir
cls
set test=0
echo (current location: %savloc%)
echo What do you want your new location to be?
set /p dir=#
echo set test=1 > "%dir%\testfile.bat"
call "%dir%\testfile.bat"
If EXIST "%dir%\testfile.bat" (
echo Valid Location! (current location: %dir%)
pause >nul
echo set savloc=%dir%> Settings\files.bat
call Settings\files.bat
del "%dir%\testfile.bat"
goto menu
)
iF NOT EXIST "%dir%\testfile.bat" (
echo Invalid Location, Please redo This step. (reset location to: %cd%)
pause >nul
echo set savloc=%cd%> Settings\files.bat
call Settings\files.bat
del "%dir%\testfile.bat"
goto menu
)
goto menu
:setcolor
cls
echo What do you want the color to be?
echo.
set /p clr=#
color %clr%
echo color %clr%>"%savloc%\color.bat"
goto menu
我尝试使用“test”变量,将其保存到该目录然后读取,而不是:
If EXIST "%dir%\testfile.bat" (
和
If NOT EXIST "%dir%\testfile.bat" (
但这也行不通。
我真的希望有人可以帮助我。
更新: 现在我将声明改为:
if exist "%dir%" (
echo Valid Location! (current location: %dir%)
pause >nul
echo set savloc=%dir%> Settings\files.bat
call Settings\files.bat
goto menu
) else (
echo Invalid Location, Please redo This step. (reset location to: %cd%)
pause >nul
echo set savloc=%cd%> Settings\files.bat
call Settings\files.bat
goto menu
)
goto menu
但是现在当目录无效时,它只是将它回显到settings \ files.bat中 它没有说什么。
答案 0 :(得分:0)
在测试目录之前,您正在回复%dir%\testfile.bat
。
当目录无效时,重定向无效,您将收到错误消息。
首先检查目录是否存在。修复示例:
set /p dir=#
If NOT EXIST "%dir% ( echo "%dir% does not exist
goto menu
)
rem now echo has a chance to work
echo set test=1> "%dir%\testfile.bat"
call "%dir%\testfile.bat"