批处理文件嵌套for循环以识别共享

时间:2016-05-20 18:29:13

标签: windows batch-file network-shares

我有以下情况

    @echo off
    for %%x in (
    machine1
    machine2
    machine3

for %%y in (
    A
    B
    C
    D
           )
              )

    do
    (
    echo machine is %%x

    \\%%x\%%y

    )

我实际上正在检查股票是否开启

\\ machine1 \ A,\\ machine1 \ B,等等..

你们可以帮助我进行巢穴循环吗?

2 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你想循环通过一堆计算机,并在每台计算机上循环通过一堆驱动器号来查看驱动器是否共享?如果是这样,你真的很亲密。您只需使用IF EXIST来检查您正在构建的路径是否已共享。

@echo off
FOR %%x IN (machine1, machine2, machine3) DO (
    echo Checking shares on machine: %%x
    FOR %%y IN (A, B, C, D) DO (
        echo Testing share: \\%%x\%%y
        if exist \\%%x\%%y (echo Shared) else (echo Not Shared)
   )
)

答案 1 :(得分:0)

试试这个:

@echo off
for %%x in ( "machine1", "machine2", "machine3" ) do (
    echo machine is %%x
    for %%y in ( "A", "B", "C", "D" ) do (
        echo share is \\%%x\%%y
    )
)