batch script with FOR does not work

后端 未结 1 871
清酒与你
清酒与你 2021-01-28 19:38

I need help with my script below:

It does not continue for the next row of machine.txt If I put the \")\" after \"echo !machine\", it shows the machines inside the machi

相关标签:
1条回答
  • 2021-01-28 20:04

    You cannot use goto within the for body as goto breaks the for loop context.

    I would place your labelled sections :64bits and :32bits into sub-routines and call them:

    @echo off
    set server=\\server01\share
    
    dir /B /O %server% | find "i32" | more +2 > 32.txt
    FOR /F "tokens=*" %%A in (32.txt) do SET file32=%%A
    
    dir /B /O %server% | find "i64" | more +2 > 64.txt
    FOR /F "tokens=*" %%B in (64.txt) do SET file64=%%B
    
    setlocal EnableDelayedExpansion
    
    for /F "tokens=*" %%C in (machines.txt) do (
      set "machine=%%C"
      echo !machine!
      if exist "\\!machine!\c$\Program Files (x86)" (
        call :64bits
      ) else (
        if exist "\\!machine!\c$\Arquivos de Programas (x86)" (
          call :64bits
        ) else (
          call :32bits
        )
      )
      echo Finished !micro!
    )
    pause
    endlocal
    exit /B
    
    :64bits
    xcopy /D /Y /F /C %server%\%file64% \\!machine!\c$\
    PsExec.exe -d \\!machine! "C:\%file64%" /q
    exit /B
    
    :32bits
    xcopy /D /Y /F /C %server%\%file32% \\!machine!\c$\
    PsExec.exe -d \\!machine! "C:\%file32%" /q
    exit /B
    

    Note: I did not check the purpose nor the logic of your script, I just fixed the for/goto issue.

    0 讨论(0)
提交回复
热议问题