首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >For /f批处理循环失败,错误为")此时是意外的。“

For /f批处理循环失败,错误为")此时是意外的。“
EN

Stack Overflow用户
提问于 2014-09-04 22:26:17
回答 1查看 193关注 0票数 1

我正在写什么,我认为将是一个简单的批处理,将循环通过一个.txt输入文件通过一个“为/F”来检查3个文件位置的PC的数量将决定操作系统或应用程序的版本,设置几个变量,然后重命名一个文件,并复制一个新的文件在它的place..But我不能得到它的工作。批处理失败,此时出现意外错误

任何帮助都将不胜感激。以下是批处理内容

代码语言:javascript
运行
复制
CD /D "C:\Win32app\Scripts\SEPXML"
FOR /f "Tokens=1" %%a IN (List.txt) DO (
    Echo %%a
    If exist "\\%%a\c$\Documents and Settings\All Users\Application Data\Symantec\Symantec Endpoint Protection\CurrentVersion\Data\Config\SyLink.xml" (GoTo :Win2k3) else (GoTo :Next1)
    :Next1
    If exist "\\%%a\c$\Win32app\Symantec\SEPP\SyLink.xml" (GoTo :x86Serv) else (GoTo :Next2)
    :Next2
    If exist "\\%%a\c$\ProgramData\Symantec\Symantec Endpoint Protection\CurrentVersion\Data\Config\sylink.xml" (GoTo :Win2K8) else (GoTo :WriteError)

    :Win2k3
    Set SyLinkPath="\\%%a\c$\Documents and Settings\All Users\Application Data\Symantec\Symantec Endpoint Protection\CurrentVersion\Data\Config"
    Set OSVer=Win2k3
    GoTo :Run

    :x86Serv
    Set SyLinkPath="\\%%a\c$\Win32app\Symantec\SEPP"
    Set OSVer=Win2k3OLD
    GoTo :Run

    :Win2K8
    Set SyLinkPath="\\%%a\c$\ProgramData\Symantec\Symantec Endpoint Protection\CurrentVersion\Data\Config"
    Set OSVer=Win2k8
    GoTo Run

    :Run
    Ren %SyLinkPath%\SyLink.xml %SyLinkPath%\SyLink.old
    Robocopy C:\Win32app\Scripts\SEPXML\SyLink %SyLinkPath% /r:0 /W:0 /copyall /Tee /Log+:C:\Win32app\Scripts\SEPXML\Log\Results.txt
    GoTo End

    :WriteError 
    Echo %%a >>C:\Win32app\Scripts\SEPXML\Log\Error-Servers.txt
    :End
)
EN

回答 1

Stack Overflow用户

发布于 2014-09-04 22:56:00

不是所有的东西都需要用括号括起来,但有一个更大的问题。

每次在for循环中执行goto时,所有循环都会被取消。你不能在一段代码中跳转。

您可以将处理移动到标签以调用或重构代码,以避免跳转操作

代码语言:javascript
运行
复制
CD /D "C:\Win32app\Scripts\SEPXML"

for /f "tokens=1" %%a in (List.txt) do (
    set "done="
    for %%b in (
        "\\%%a\c$\Documents and Settings\All Users\Application Data\Symantec\Symantec Endpoint Protection\CurrentVersion\Data\Config"
        "\\%%a\c$\Win32app\Symantec\SEPP"
        "\\%%a\c$\ProgramData\Symantec\Symantec Endpoint Protection\CurrentVersion\Data\Config"
    ) do if not defined done if exist "%%~b\sylink.xml" (
        set "done=1"
        Ren "%%~b\SyLink.xml" "SyLink.old"
        Robocopy C:\Win32app\Scripts\SEP-XMLChange\SyLink "%%~b" /r:0 /W:0 /copyall /Tee /Log+:C:\Win32app\Scripts\SEP-XMLChange\Log\Results.txt
    )
    if not defined done (
        Echo %%a >>C:\Win32app\Scripts\SEP-XMLChange\Log\Error-Servers.txt
    )
)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25668047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档