Reputation: 43
I am trying to concatenate several files together using a Windows batch file to make a single image of the files. Now, I have found this can be done using copy "copy file1+file2+file3+file4 FileConcat" but what I want to do is to start file1 @ byte address 00, then start file2 @ byte address 999424, start file3 @ byte address 3997696 and file4 @ byte address 4001536. I can do this in Linux using the following but is there a way to do this in windows without writing a specific application? Any help, much appreciated.
set COMBINEDFILE=IMAGE/combined.srec
dd conv=notrunc bs=1 if=INPUT/FILE1.srec of=$COMBINEDFILE seek=0
dd conv=notrunc bs=1 if=INPUT/FILE2.xap of=$COMBINEDFILE seek=999424
dd conv=notrunc bs=1 if=INPUT/FILE3.html of=$COMBINEDFILE seek=3997696
dd conv=notrunc bs=1 if=INPUT/FILE4.js of=$COMBINEDFILE seek=4001536
Thank you for any help
Upvotes: 1
Views: 3354
Reputation: 1
When you add the following code at the beginning of the Batch file script that LS_DE provided. Then you don't need to create anything but this batch files. If the files already are created.
This code created the 'empty' PAD files with the length. I have validated this to be working without any issues.
fsutil file createnew %~dp01.PAD 1
fsutil file createnew %~dp010.PAD 10
fsutil file createnew %~dp0100.PAD 100
fsutil file createnew %~dp01000.PAD 1000
fsutil file createnew %~dp010000.PAD 10000
fsutil file createnew %~dp0100000.PAD 100000
Upvotes: 0
Reputation: 43
I have an alternative answer to LS_dev's answer but it is based on his answer so I can't take any credit for it. Instead of generating padding using multiple padding files in a loop I generate an empty file based on the padding needed and append this to the file. I am not a full time programmer so maybe there are "issues" with doing it this way. If you are using a win7 machine, you need admin privileges to run this script. It's fsutil that needs admin rights to run. Thanks again LS_dev
PADOUT.BAT
@ECHO OFF
IF %2.==. GOTO :Syntax
IF NOT %3.==. GOTO :Syntax
SET /A _size=1*%2
del padding.txt
SET /A _Left=%_Size%-%~z1
fsutil file createnew %cd%\padding.txt %_Left%&&goto:eof
:Syntax
ECHO generates padding file to make file specific size
ECHO Syntax: PADOUT filepath size
GENERATE.BAT
del IMAGE\combined.srec
SET COMBINEDFILE= IMAGE\combined.srec
COPY INPUT\lwip_140_echo_server.elf.srec %COMBINEDFILE%
CALL PADOUT.BAT %COMBINEDFILE% 999424-1
COPY %COMBINEDFILE%+padding.txt+INPUT\MPDU1_Read.xap /b %COMBINEDFILE%
CALL PADOUT.BAT %COMBINEDFILE% 3997696-1
COPY %COMBINEDFILE%+padding.txt+INPUT\MPDU1_ReadTestPage.html %COMBINEDFILE%
CALL PADOUT.BAT %COMBINEDFILE% 4001536-1
COPY %COMBINEDFILE%+padding.txt+INPUT\Silverlight.js %COMBINEDFILE%
Upvotes: 1
Reputation: 11151
I only know methods for appending files in standard batch, none for truncation.
If input files don't need to be truncated, they can be added and them padded to fill empty spaces.
For this to work, you will need 1 byte size padding file (1.pad
) as well as - for performance improvement - 10, 100, 1000, 10000 and 100000 bytes size padding files.
PADFILE.BAT
- utility batch to pad your files:
@ECHO OFF
IF %2.==. GOTO :Syntax
IF NOT %3.==. GOTO :Syntax
SET /A _size=1*%2
:CheckSize
SET /A _Left=%_Size%-%~z1
IF %_Left% LSS 0 1>&2 ECHO File already bigger than size!&TYPE 2>NUL&GOTO :EOF
IF %_Left% == 0 GOTO :EOF
IF %_Left% GEQ 100000 TYPE 100000.PAD>>%1&&GOTO:CheckSize
IF %_Left% GEQ 10000 TYPE 10000.PAD>>%1&&GOTO:CheckSize
IF %_Left% GEQ 1000 TYPE 1000.PAD>>%1&&GOTO:CheckSize
IF %_Left% GEQ 100 TYPE 100.PAD>>%1&&GOTO:CheckSize
IF %_Left% GEQ 10 TYPE 10.PAD>>%1&&GOTO:CheckSize
TYPE 1.PAD>>%1
GOTO :CheckSize
:Syntax
ECHO Pads file until desired size.
ECHO Syntax: PADFILE filepath size
Now your commands would look like:
SET COMBINEDFILE=IMAGE/combined.srec
COPY INPUT/FILE1.srec %COMBINEDFILE%
PADFILE.BAT %COMBINEDFILE% 999424
COPY %COMBINEDFILE%+INPUT/FILE2.xap
PADFILE.BAT %COMBINEDFILE% 3997696
COPY %COMBINEDFILE%+INPUT/FILE3.html
PADFILE.BAT %COMBINEDFILE% 4001536
COPY %COMBINEDFILE%+INPUT/FILE4.js
Remember that at least 1.PAD
should be placed in same folder as PADFILE.BAT
.
For fast creation of other .PAD
files from 1.PAD
you can use:
(FOR /L %I IN (1,1,10) DO @TYPE 1.PAD)>10.PAD
(FOR /L %I IN (1,1,10) DO @TYPE 10.PAD)>100.PAD
(FOR /L %I IN (1,1,10) DO @TYPE 100.PAD)>1000.PAD
(FOR /L %I IN (1,1,10) DO @TYPE 1000.PAD)>10000.PAD
(FOR /L %I IN (1,1,10) DO @TYPE 10000.PAD)>100000.PAD
Upvotes: 0