Two files (binary or non-binary) can be joined to one file in a specific manner with a specific divider string between them, using only console commands. Later the second file can be extracted by the following simple method°, again using only console commands:
@echo off
setlocal enableextensions enabledelayedexpansion
REM === JOINING FILES ===
REM Divider.txt must consist of a line starting with "di-vi-der"
REM preceeded by at least one line and followed by a blank line.
echo This is a necessary preceeding line. > Divider.txt
echo di-vi-der This line must be followed by a blank line. >> Divider.txt
REM Join files to Joined.bin by one of these two methods:
REM copy /b FirstFile.exe + /a Divider.txt + /b File2BeExtracted.exe /b Joined.bin
type FirstFile.exe Divider.txt File2BeExtracted.exe > Joined.bin
REM === UNJOINING FILES ===
REM Get the line number of the dividing line in Joined.bin:
for /F "delims=:" %%a in ('findstr /N "^di-vi-der" "Joined.bin"') do set "lines=%%a"
REM Extract the part of the Joined.bin following the divider line:
< "Joined.bin" (
REM Pass thru the first lines:
for /L %%i in (1,1,%lines%) do set /P "="
REM Copy the rest to Output.bin:
findstr "^"
) > Output.bin
This is working nearly perfectly.
My first (and main) problem is: findstr adds 0D 0A at the end of the last line written to Output.bin. How this could be corrected?
A second problem could be: Due to some restrictions for the findstr command (max. length of lines) this method could fail in some (rare?) cases. To detect such cases, the file size of File2BeExtracted.exe could be determined and stored in the divider line for a final check of identity after extracting the file. How this could be done?