The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Combine Files in VB6

I'm looking for VB code to combine a couple of flatfiles into one big file.  Basically loop through a directory and copy and paste the content of the files into a new file.
Does anybody have (or know of) samplecode for this?
Many thanks.
Celeste L Send private email
Monday, October 10, 2005
 
 
Try here,  they have lots of goodies:

http://planetsourcecode.com/
Nick Koranda Send private email
Monday, October 10, 2005
 
 
VBNet has some examples as well.

http://vbnet.mvps.org/
Eric D. Burdo Send private email
Monday, October 10, 2005
 
 
You probably want something like this

Private Function FileBytes(ByVal FileName as String) As Byte()
  Dim FBytes() as Byte
  Dim FileHandle as Integer
  ReDim FBytes(FileLen(FileName) - 1)
  FileHandle=FreeFile
  Open FileName For Binary Access Read As FileHandle
      Get FileHandle, , FBytes()
  Close FileHandle
  FileBytes = FBytes
End Function

Private Sub MergeFiles(ByVal MergeName as String, FileList as Collection)
  Dim FileHandle as Integer
  Dim TempS as String
  Dim tBytes() as Byte

  FileHandle =FreeFile
  Open MergeName For Binary Access Write As FileHandle
    For each TempS in FileList
        tBytes = FileBytes(TempS)
        Put FileHandle, , tBytes()
    Next TempS
  Close FileHandle
End Sub
Rob Conley Send private email
Monday, October 10, 2005
 
 
It works!  Thank you so much Rob Conley!!
Celeste L Send private email
Tuesday, October 11, 2005
 
 
Not to be slightly off topic, but doesnt TempS need to be a variant that is CStr(TempS)?  I have always had issues with extracting explicitly declared strings from a collection.  I had to use a variant and type cast it to a string.
Nick Koranda Send private email
Tuesday, October 11, 2005
 
 
just use shell and do a OS copy command
(cmd.exe copy file1+file2+file3 destfile)
DJ
Tuesday, October 11, 2005
 
 
I didn’t use a collection, got my files from  a FileListBox.
Instead of  “For each TempS in FileList” I used a “For I =0 to myFileListBox.ListCount – 1”

More that one way to skin a cat.
Celeste L Send private email
Wednesday, October 12, 2005
 
 
Yup TempS needs to be Variant my bad.
Rob Conley Send private email
Wednesday, October 12, 2005
 
 
----------------
“For each TempS in FileList” I used a “For I =0 to myFileListBox.ListCount – 1”
-----------------

That will work but long ago I learn that directly accessing controls for pure code routines is a sure way to hell for maintance and reusability. In this case you are relying on the list of files being stored in a FileListBox.

I strongly recommend making a collection or array first then passing it to a function on the form. That way if you need it on another form, switch to VB.NET, it is a copy and paste step to reuse the code.

It also easier to debug in that it separate a problem with the file list box from problems in the code.

Granted in this instance the difference are trival but doing it consistently over the long haul makes thing a lot easier
Rob Conley Send private email
Wednesday, October 12, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz