在批处理命令中使用目录变量

问题描述 投票:0回答:1

我是批处理命令的新手。我写了以下代码:

for /D %%G in ("C:\CI\workspace\MP*") do (
  if exists "%%~nG\DirecotoryPortal\" (
     CD "DirecotoryPortal"
     echo DirectoryPortal Exists
  )
)

此时出现意外的错误“%~nG\DirecotoryPortal”。 我不知道如何在循环中使用 %%G 。我想采用这个路径并与“DirecotoryPortal”连接并检查该目录是否存在。

batch-file
1个回答
0
投票

这应该有效,并且应该迭代 C:\CI\workspace 中与模式 MP* 匹配的目录。

for /D %%G in ("C:\CI\workspace\MP*") do (
  if exist "%%G\DirectoryPortal\" (
     CD /D "%%G\DirectoryPortal"
     echo DirectoryPortal Exists in %%G
  )
)
© www.soinside.com 2019 - 2024. All rights reserved.