2013-11-21 76 views
0

我需要使用以下我的脚本帮助:用FOR批处理脚本不起作用

它不会持续machine.txt 的下一行。如果我把“)!”“机器回声”之后,显示machine.txt中的机器,因此,它的工作原理!

但当“)”是在脚本不会继续,出口的尽头..

@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)" goto 64bits 
    goto goo 

    :goo 
    if exist "\\!machine!\c$\Arquivos de Programas (x86)" goto 64bits 
    goto 32bits 

    :64bits 
    xcopy /D /Y /F /C %server%\%file64% \\!machine!\c$\ 
    PsExec.exe -d \\!machine! "C:\%file64%" /q 
    goto end 

    :32bits 
    xcopy /D /Y /F /C %server%\%file32% \\!machine!\c$\ 
    PsExec.exe -d \\!machine! "C:\%file32%" /q 
    goto end 

    :end 
    echo Finished !micro! 
) 
pause 

任何想法?谢谢!

+0

请编辑您的帖子,使代码更具可读性。 – Josh

+0

是的,我知道,但是当我输入时确定,但在其下方显示没有跳线...我不知道如何解决它。 – diegoww

+0

我懂了!编辑... – diegoww

回答

0

您不能在for正文中使用goto,因为goto会中断for循环上下文。

我把你的标记部分:64bits:32bits成子例程和call他们:

@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 

注:我没有检查的目的,也没有脚本的逻辑,我只是​​固定for/goto问题。