0

我想在这部分为这段代码添加另一条指令,"if exist "%%d:\%folder%\" (echo Device was found on %%d:)"所以如果找到该文件夹​​,它也set folderfound="%%d:\%folder%\"可以做类似的事情吗?这是完整的代码来显示我想要做什么

:autodetect1    
set /p "folder=Folders Name that the photo's are in: "

    setlocal
    set folder=%1
    if "%folder%" == "" call :autodetect1
    cls
    for %%d in (d e f g h i j k l m n o p q r s t u v w x y z) do (
          if exist "%%d:\%folder%\" ( 
              echo Device was found on %%d: and set folderfound=%%d:\%folder%\
          ) else (
              echo Device was not found on %%d:
          )
    )

我在论坛上阅读,我发现提到你可以使用 && 直接执行另一个命令我可以在 if 存在中使用它吗?

4

1 回答 1

0

在以下代码中使用“and”的地方使用“&&”似乎设置了 folderfound 变量:

@echo off
:autodetect1
set /p "folder=Folders Name that the photo's are in: "
    rem goto :eof
    rem setlocal
    rem set folder=%1
    rem if "%folder%" == "" call :autodetect1
    rem cls
    for %%d in (d e f g h i j k l m n o p q r s t u v w x y z) do (
          if exist "%%d:\%folder%\" ( 
              echo Device was found on %%d: && set folderfound=%%d:\%folder%\
          ) else (
              echo Device was not found on %%d:
          )
    )

我已经注释掉了我不明白的部分。

您需要了解这里发生了什么,转到http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx并向下滚动到“使用多个命令和条件处理符号"

于 2012-08-25T08:45:13.967 回答