WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Operations

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Merge Files with Binary Functions

Keywords: 	  merge all files combine files

Question:

How do I use the Binary functions to merge a bunch of files in one directory into one big file?

Answer:

DirChange("c:\backup")
dsize=DirSize("C:\backup",1)
;message("",dsize)


binbuf2=BinaryAlloc(dsize+100)
allfiles=FileItemize("*.*")
count=ItemCount(allfiles,@tab)

For i=1 to count
   eachfile=ItemExtract(i,allfiles,@tab)
   fs1 = FileSize(eachfile)
   binbuf1 = BinaryAlloc(fs1)
   
   BinaryRead(binbuf1, eachfile)
   a2=BinaryCopy(binbuf2, BinaryEodGet(binbuf2), binbuf1, 0, fs1)
   
   binbuf1 = BinaryFree(binbuf1)
Next
BinaryWrite(binbuf2, "C:\backup\MergedFile.txt")
binbuf2 = BinaryFree(binbuf2)

Article ID:   W15497
File Created: 2003:05:13:11:28:18
Last Updated: 2003:05:13:11:28:18