1

以下情况:我有一个包含 140 个协议文件的文件夹,格式如下(我审查了其中一些)

    LÖSCHPROTOKOLL

HDShredder 3.2
licenses for
%Corporation%
%address%
%address%

Drive: %numbers and letters%
Controller: IDE #0
Kanal: Primary 
Gerät: Master   
LUN: N/A
serial number: %numbers and letters% 
Größe: 78165360 Sektoren (38166 MB)   

HDShredder gestartet am 2.01.2012 um 14:48:46
Verwendete Löschmethode: %deletion methode% (Standard)

Durchlauf 1 von 3 gestartet um 14:48:46
Lösche
Muster: FFFFFFFF
Durchlauf 2 von 3 gestartet um 15:02:34
Lösche
Muster: 00000000
Durchlauf 3 von 3 gestartet um 15:16:23
Lösche
Muster: 55555555
Beendet am 2.01.2012 um 15:30:12

END OF FILE

然而,这些文件被命名为SHRED001.LOG SHRED002.LOGetc,我喜欢用序列号重命名它们。

这是我到目前为止尝试过的

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

echo test


for %%d in (C:\Protokolle\protokolle\SHRED*) do (
    for /F "skip=13 eol=; delims=?" %%i in (%%d) do (
      echo %%i >> C:\Protokolle\protokolle\liste.txt    
      echo %%i
    )
)

完成后,它应该如上所述重命名文件(尚未实现)并收集外部文件中的所有数字liste.txt

但是当我开始批处理时,我得到的只是一个无穷无尽的文本文件,以一个序列号开头,所有文本文件的内容组合在一起。

希望有人有想法。问候 :)

4

2 回答 2

3

您的内部 for 循环for /F "skip=13 eol=; delims=?" %%i in (%%d) do (将遍历给出的文件中的所有行%%d,省略前 13 行(参考)。这就是为什么输出看起来像你描述的那样。如果我理解正确,您只想解析以字符串开头的行serial number:- 您可以通过使用FINDSTR( reference ) 来实现。我尝试编写脚本,包括重命名您:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR %%d IN ("C:\Protokolle\protokolle\SHRED*") do (
    FOR /F "tokens=2 delims=:" %%i IN ('FINDSTR /c:"serial number" "%%d"') DO (
       ECHO %%i
       :: copy string for string manipulation
       SET tmp=%%i
       :: get rid of leading space
       SET serial=!tmp: =!
       :: log serial to list file
       ECHO !serial! >> "C:\Protokolle\protokolle\liste.txt"
       :: rename file
       MOVE "%%d" "C:\Protokolle\protokolle\SHRED!serial!.log"
    )
)
于 2013-02-27T13:14:48.733 回答
0

这是完成的工作脚本,感谢您的帮助:)

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET /A files=0
SET /A todo=0

::  Checking wheather a log-file exists
::  If not: Error message and exit.
IF NOT EXIST .\SHRED* (
    ECHO No matching logfile found.
    ECHO Exit!
    ECHO.
    PAUSE
    EXIT
)

::for the "loading Screen"
@FOR %%e in (".\SHRED*") do set /A files=files+1
ECHO !files! Files found!
:: waiting... this way we avoid the need of pressing a button
PING 127.0.0.1 -n 3 > NUL

FOR %%d IN (".\SHRED*") do (
    ::  Checking for a "Seriennummer"-String and copying everything after it
    FOR /F "tokens=2 delims=:" %%i IN ('FINDSTR /c:"serial number" "%%d"') DO (
        CLS
        ::    for the "loading Screen"
        SET  /A todo=todo+1
        ::   copy string for string manipulation
        SET  tmp=%%i
        ::   get rid of leading space
        SET  serial=!tmp: =!
        ::   delete the last character of the string
        SET  serial=!serial:~0,-1!
        ::   ECHOing of the serial and the "loading screen"
        ECHO !serial! !todo! von !files!
        ::   log serial to list file
        ECHO !serial!>> ".\1Uebersicht.txt"
        ::   rename file
        MOVE "%%d" ".\!serial!.log"
    )
)

::  checking if there is still a log-file left
IF EXIST ".\SHRED*" (
    ECHO An error occoured.
    ECHO Not all log-files were renamed
    ECHO.
    PAUSE
    EXIT
)

CLS
ECHO !files! files renamed.
ECHO overview list created.
ECHO please refresh the directory
ECHO.
PAUSE
于 2013-03-04T08:16:40.653 回答