PDA

View Full Version : how to batch concatenate files in dos?


b66pak
1st September 2010, 20:58
hi,


i have a folder with files like this:

part001.xyz.bin
part002.xyz.bin
part003.xyz.bin
part004.xyz.bin
.
.
.
partnnn.xyz.bin

i need a line for DOS to join this files like this:

copy/b part001.xyz.bin+part002.xyz.bin+part003.xyz.bin+part004.xyz.bin+...+partnnn.xyz.bin final.xyz.bin


can anyone help?
_

Groucho2004
1st September 2010, 21:49
DOS? Why can't you use the same command line in a console instance in Windows?

LoRd_MuldeR
1st September 2010, 22:10
XCopy, maybe?

Groucho2004
1st September 2010, 22:44
XCopy, maybe?

Are you just guessing? Looking at the xcopy reference I don't see any feature that would assist in building this command line.

I suppose there is some way to realise this with console commands but my knowledge doesn't go far beyond "for %i in ..." loops. Anything more complex I just write a small c or c++ tool.

Anyway, I'm still a bit confused about the "DOS" reference. Unless he/she actually means a console in Windows... :rolleyes:

LoRd_MuldeR
2nd September 2010, 00:40
I was just guessing, because AFAIK the "xcopy" command was available on the original MS-DOS, but apparently xcopy cannot do that :o

And I'm pretty sure he refers to the actual MS-DOS, not the Windows Command-Prompt. He says he want's something like "copy /b file1 + file2 joined", only for DOS.

If he was in the Windows Command-Prompt, then "copy /b file1 + file2 joined" would work as-is just fine and his question would be superfluous...

(My next idea would be something like the good old Norton Commander)

Groucho2004
2nd September 2010, 08:07
He says he want's something like "copy /b file1 + file2 joined", only for DOS.

But this works just as well under DOS. I checked this with MS-DOS 7.1. I would imagine that any other recent version of DOS supports it.

J_Darnley
2nd September 2010, 11:15
If you're asking for an automatic way of generating that line, try this in a batch file.
setlocal enabledelayedexpansion
FOR %%A IN (*.bin) DO set VAR=!VAR!+%%A
echo copy /b %VAR:~1% final.bin
I can't say whether it works in real DOS but if it does, the copy command should get printed, then you can just remove the echo.

Groucho2004
2nd September 2010, 11:32
But what about the order of the files?

They will be processed as they are found on the disk (i.e. the order in which they are in the File Allocation Table) which is not necessarily the order in which they should be concatenated.

J_Darnley
2nd September 2010, 15:15
What do you mean? The files are in order for the names he described. If he needs some other order, he can use the dir command. If he needs some random order then no amount of scripting will help him, he could have typed them all out by now.

Groucho2004
2nd September 2010, 16:09
What do you mean? The files are in order for the names he described.

OK, here's an example:

I have the files 001.bin, 002.bin, 003.bin and 004.bin. I copy them to a FAT drive in this order (for whatever reason):
004.bin
002.bin
003.bin
001.bin

The "for %i in (*.bin)..." command will read them in the same order as I copied them, i.e. not alphabetically.

I tried the same on a NTFS drive but there it doesn't seem to matter in which order I copy the files.

This is getting quite academical so let's see if the OP will even get back here and elaborate a bit further.

b66pak
2nd September 2010, 18:08
If you're asking for an automatic way of generating that line, try this in a batch file.
setlocal enabledelayedexpansion
FOR %%A IN (*.bin) DO set VAR=!VAR!+%%A
echo copy /b %VAR:~1% final.bin
I can't say whether it works in real DOS but if it does, the copy command should get printed, then you can just remove the echo.

thanks a lot...it works perfect...

i made a mistake asking for DOS...i wanted a solution for win cmd...i use NTFS...the order is as described...
_