gpt4 book ai didi

windows - 针对变量的管道添加 "if arguement"

转载 作者:可可西里 更新时间:2023-11-01 11:08:28 26 4
gpt4 key购买 nike

我是编写代码和批处理文件的新手。我正在尝试通过允许用户发出以下批处理文件来自动执行用户设置:

执行的命令 = "BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237"

@echo off
::Conditions leading to errors if the batch script is not executed correctly
if "%1"=="" and "%2"=="" goto error1
if "%1"=="" goto error2
if "%2"=="" goto error3

::Allows user to set the "Source Path" to copy the testcase files from
set source=%1
::Allows user to set the "Destination Path" to copy the testcase files from
set IP_Address=%2

::Tells the user what the "Source" and "Destination" Paths are
echo Source Path = %1
echo Destination Path = %2
echo.
powershell.exe -File "bat_script.ps1" %1 %2 -NoProfile -NoExit


goto end
:error1
echo.
echo Error Syntax: BVT_AudioDecode_Setup.bat "Source_Path\AudioDecode_Testcase_Folder" "Device IP Address"
echo.
echo For example: BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237
echo -or-
echo BVT_AudioDecode_Setup.bat C:\WP\BVT\Audio\Decode 10.42.233.237
echo.
echo.
goto end
:error2
echo.
echo Error Syntax: BVT_AudioDecode_Setup.bat "Source_Path\AudioDecode_Testcase_Folder" "Device IP Address"
echo.
echo For example: BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237
echo -or-
echo BVT_AudioDecode_Setup.bat C:\WP\BVT\Audio\Decode 10.42.233.237
echo.
echo.
goto end
:error3
echo.
echo Error Syntax: BVT_AudioDecode_Setup.bat "Source_Path\AudioDecode_Testcase_Folder" "Device IP Address"
echo.
echo For example: BVT_AudioDecode_Setup.bat V:\WP\BVT\Audio\Decode 10.42.233.237
echo -or-
echo BVT_AudioDecode_Setup.bat C:\WP\BVT\Audio\Decode 10.42.233.237
echo.
echo.
goto end
:end

这已经过测试并且有效。

现在我正在尝试添加/测试一个简单的代码块,但找不到正确的语法。是的,过去 3 个小时我一直在谷歌搜索。这是我正在尝试做的事情:

执行的命令 = "Random.bat C:\Users"

执行的命令 = "Random.bat C:\InvalidDirectory"

::Conditions leading to errors if the batch script is not executed correctly
@ECHO OFF
SET "mypath=%1"
ECHO %mypath%
cd %mypath% | find "%invalidpath%"
Echo %invalidpath%

If "%invalidpath%=The system cannot find the path specified." (
goto error1)
else (
goto BeginTest)

::Begins the testcase
:BeginTest
::Do some stuff
goto end
:error1
echo Error: Invalid Path
goto end
:end

如果有人能指出我正确的方向,将不胜感激...

最佳答案

您可以使用 IF EXIST 语句来检查目录是否存在。例如,要测试 C:\WIN,如果存在则更改为 C:\WIN:

C:
IF NOT EXIST "C:\WIN\." GOTO NOWINDIR
CD \WIN
:NOWINDIR

关于windows - 针对变量的管道添加 "if arguement",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15308075/

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