我正在写什么,我认为将是一个简单的批处理,将循环通过一个.txt输入文件通过一个“为/F”来检查3个文件位置的PC的数量将决定操作系统或应用程序的版本,设置几个变量,然后重命名一个文件,并复制一个新的文件在它的place..But我不能得到它的工作。批处理失败,此时出现意外错误
任何帮助都将不胜感激。以下是批处理内容
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
)发布于 2014-09-04 22:56:00
不是所有的东西都需要用括号括起来,但有一个更大的问题。
每次在for循环中执行goto时,所有循环都会被取消。你不能在一段代码中跳转。
您可以将处理移动到标签以调用或重构代码,以避免跳转操作
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
)
)https://stackoverflow.com/questions/25668047
复制相似问题