回答:
これを試して:
@ECHO OFF
REM --------------------------------------------------------------------------------
REM Check for and create VDir under Default Web Site
REM
REM %1 is the VDIR to create
REM %2 is the Physical path to the VDIR
REM --------------------------------------------------------------------------------
IF "%1"=="" GOTO Syntax
IF "%2"=="" GOTO Syntax
ECHO Running...
ECHO AppCmd.exe list vdir "Default Web Site/%1/"
ECHO.
AppCmd.exe list vdir "Default Web Site/%1/"
IF %errorlevel%==1 GOTO Exists
ECHO.
ECHO Running...
ECHO AppCmd.exe ADD vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2
ECHO.
AppCmd.exe ADD vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2
GOTO End
:Exists
ECHO.
ECHO VDir already exists
ECHO.
GOTO End
:SYNTAX
ECHO.
ECHO VDir Name and Physical Path Required
ECHO.
ECHO CreateVDir.CMD ^<VDirName^> C:\PhysPath
ECHO.
:END
これを試して。ほとんどはChristopher_G_Lewisによって与えられた答えと同じですが、エラーコードの代わりにリスト出力の解析に依存しています。
また、cmd.exeシェル構造Aを使用します。B(Aが失敗した場合はBを実行)
@ECHO OFF
REM --------------------------------------------------------------------------------
REM Check for and create VDir under Default Web Site
REM
REM %1 is the VDIR to create
REM %2 is the Physical path to the VDIR
REM --------------------------------------------------------------------------------
IF "%1"=="" GOTO Syntax
IF "%2"=="" GOTO Syntax
AppCmd.exe list vdir "Default Web Site/%1/" | findstr /I "Default Web Site/%1/" || AppCmd.exe add vdir /app.name:"Default Web Site/" /path:/%1 /physicalPath:%2
goto :eof