在batch file中嵌套的IF有问题

我正在制作一个batch file,用于检出SVN中的项目。 我要求用户input目录,当你到达你想要的目录时,inputcheckout并检出项目目录。 但是,我在下面的代码有一些麻烦。 请帮忙。

if /i %choice%==1 ( cls svn ls %svnroot_temp% :top set /p direct=Enter directory: if %direct%=checkout( goto :checkout_area ) set svnroot_temp= %svnroot_temp%/%direct% svn ls %svnroot_temp% goto :top ) 

我在哪里错了?

()圆括号内的命令块中不要使用:label:: label-like commentcertificate

 @ECHO %1>NUL if "" == "" ( @echo a simple echo, no comments ) if ""=="" ( @echo a rem comment follows this echo command rem comment @echo a rem comment precedes this echo command ) if ""=="" ( @echo a label-like comment follows this echo command :: comment @echo a label-like comment precedes this echo command ) if ""=="" ( @echo a label follows this echo command :label @echo a label precedes this echo command ) 

输出

 ==>D:\bat\labels.bat OFF a simple echo, no comments a rem comment follows this echo command a rem comment precedes this echo command a label-like comment follows this echo command '@echo' is not recognized as an internal or external command, operable program or batch file. a label follows this echo command '@echo' is not recognized as an internal or external command, operable program or batch file. ==> 

下一个代码片段应该按预期工作,如果我能理解你的目标:

 SETLOCAL enableextensions rem (set `svnroot_temp` and `choice` variables here) if /i "%choice%"=="1" ( cls svn ls %svnroot_temp% call :top ) goto :eof :top set /p direct=Enter directory: if /I "%direct%"=="checkout" goto :checkout_area set "svnroot_temp=%svnroot_temp%\%direct%" svn ls %svnroot_temp% goto :top :checkout_area 

请注意,比较expression式中的if /I "%direct%"=="checkout" goto :checkout_area用双引号括起来,因为任何用户input都可能包含一个空格,甚至可能保持为空。
不确定在svn ls "%svnroot_temp%"引用。

不知道"%svnroot_temp%"svn ls命令的input目录还是输出目录:

  • 在input的情况下:检查使用, if not exist "%svnroot_temp%\%direct%\" goto :top 之前更改set "svnroot_temp=%svnroot_temp%\%direct%"
  • 在输出的情况下:更改使用MD "%svnroot_temp%" 2>NUL创build它。