0

I have different types of file in the same folder, which I have filtered and redirected to a list.txt file, using a separate script.

List.txt has the name of the binary files , which I need to combine together into one binary file.

>type list.txt
a.raw
b.raw
c.raw

Concatenate all the files present in the list.txt to a final.raw file.

>type < list.txt > final.raw
 The syntax of the command is incorrect.

Please let me know if there is any option to achieve this on windows cmdline or through some script file.

Note : manually both type and copy cmd is working properly for concatenation. need a script or cmd to do the same.

1 Answers1

0

If files to be concatenated are textual, then you may use

@echo.>final.raw && @for /f %x in (list.txt) do @type "%x" >> final.raw

If files to be concatenated are binary (really - in any case), then use

@echo.>final.raw && @for /f %x in (list.txt) do @copy /b final.raw+"%x" > nul

If filenames may contain spaces then use

@echo.>final.raw && @for /f "tokens=*" %x in (list.txt) do @copy /b final.raw+"%x" > nul

If the file final.raw already exists and may NOT be cleared then remove @echo.>final.raw && from the command line.

For using in .BAT file you may double each percent sign.

Akina
  • 3,195
  • 1
  • 8
  • 9
  • Tried it in cmdline and putting it into batch file it is not working .. – mail2subhajit Nov 01 '19 at 09:56
  • In .BAT you must double percent signs. In command line - it must work, except the case when concatenated files are binary. – Akina Nov 01 '19 at 09:59
  • tried this in batch file : for /f %%x in (list.txt) do @type %%x >> final.raw, all the files are binary file. – mail2subhajit Nov 01 '19 at 10:08
  • @mail2subhajit *all the files are binary file* You should specify this in the question. Edited. – Akina Nov 01 '19 at 10:09
  • updated the question, now only the first file is taken from list.txt, other files are not getting concatenated. – mail2subhajit Nov 01 '19 at 12:00
  • @mail2subhajit *only the first file is taken from list.txt, other files are not getting concatenated.* It is strange, I have tested, and 3 binary files were successfully concatenated from the command line. – Akina Nov 01 '19 at 12:10
  • The list.txt file has data in new line or return after each file name (CRLF) ex: a.raw\n b.raw \n .. so on. I hope your list.txt also have the same. – mail2subhajit Nov 01 '19 at 12:17
  • @mail2subhajit Yes, absolutely the same. – Akina Nov 01 '19 at 12:30
  • Thanks @Akina .. i will try to figure out the problem and update it here. – mail2subhajit Nov 01 '19 at 12:57