【发布时间】:2011-04-28 01:52:28
【问题描述】:
我对 GOTO 命令和附属标签有疑问。
事实:给定文件夹中的一堆文件(它们是日志错误),我需要打开它们并检查它们是否包含特定字符串。如果是,则从文件名中删除一些字符(“_”最后一次出现后的所有字符,包括自身)并执行其他操作。
为了切断字符,我以循环方式使用 GOTO 命令,因为我发现它在这里描述:http://www.robvanderwoude.com/battech_while_loops.php
脚本是:
@echo off
setlocal EnableDelayedExpansion
cls
for %%X in (D:\e-pub\outbox\logs\*.*) do (
for /F "tokens=7" %%S in (%%X) do (
if /i "%%S"=="<ml>" (
SET fisier=%%~nX
SET cond=!fisier:~-1!
SET fisier=!fisier:~0,-1!
:loopStart
rem condition to break the loop
if !cond!==_ goto loopEnd
SET cond=!fisier:~-1!
SET fisier=!fisier:~0,-1!
goto loopStart
:loopEnd
rem here it should be out of a loop
rem other stuff to do with var !fisier!
rem the following line is not executed because of the label loopEnd
echo !fisier!
)
)
)
pause
脚本没有运行,因为标签 loopEnd 后面有一个空行?! 如果我在该标签之后编写任何指令,它们将被执行,但不会执行第一个 for 语句的其余迭代(日志错误文件夹包含多个文件)
有人可以提供帮助吗?
【问题讨论】:
-
显示您的日志文件样本,其中包含要查找的字符串,以及您需要删除的内容。显示你想要的最终输出。
-
从我的角度来看,这与内容无关,而与做事的方式有关
标签: windows file batch-file command goto