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)