As an attempt to solve this issue, I tried to design a command using two Windows CLI tools, dsfo.exe and dsfi.exe (from DS File Ops Kit). The dsfo tool can extract a block of data from a file and output it as a new file. The dsfi tool can write a block of data into an existing file. What I want is copy 16 bytes located at offset 1024 of each file in a folder full of recovered M2TS video files, paste them into a text file, and add a line break. (This should then serve as a list of search terms for WinHex.) Since each of those two aforementioned tools can only deal with one half of the process, I tried to pipe the output of the first one into the input of the second one, but I can't get the expected result -- the string copied from the first parsed file gets copied repeatedly.
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
uàý¸n6)‹Û·žB`n
...
The command used :
L:
CD "L:\HGST 4To\Extra Found Files\Multimedia Video\MPEG Transport Stream Video"
FOR %%F in (*.mts) DO (
SETLOCAL EnableDelayedExpansion
"dsfo.exe" %%F 1024 16 - | "C:\Logiciels autonomes\dsfok\dsfi.exe" "G:\HGST_recherche_fragments.txt" e 0 -
"dsfi.exe" "G:\HGST_recherche_fragments.txt" e 0 "G:\0D0A.txt"
ENDLOCAL
)
(The 0D0A.txt file contains only a line break, 0D 0A in hexadecimal. I don't know if there's a more elegant way of adding a line break into a text file using a native command, but at least that part works as intended.)
(I'm not sure if “EnabledDelayedExpansion” is even useful in that situation, I get the same result with or without. The problem seems to be with the pipe, not the looped variable : the displayed output of the command shows that the file name is correctly updated for each iteration, but for some reason the output which is piped to the second half of the command is always that of the first iteration.)
Why do I get this result, and how can I fix it ?
Is there a better way of achieving the indended result ? (E.g. a CLI tool which would be able to perform the whole operation in a single command -- like ddrescue on a Linux system, which I used once to do something similar, i.e. copy blocks of data from a file directly into another file.)
(Of course, a workaround would be to first extract the 16 bytes block from each file to an actual 16 bytes file with dsfi, then use that file as input for dsfo, but that would create thousands of intermediate files, which I'd like to avoid if at all possible -- since the goal of the whole operation is to reduce clutter I'd prefer not to add any more of it along the way.)
Thanks.