Copy a File Quickly


Visual Basic is often seen as a tool to create front end GUI intensive applications. However, it can also easily be used to do lower level tasks such as quickly copying one file to another byte by byte. This code snippet demonstrates how you can easily take one file and copy it to a second one as quickly as possible. The way it does this is by pulling the whole file into memory and then writing it back out to the second file name.

This sample demonstrates some of VB's File IO operations such as Open, Get, and Put. It also demonstrates how you can declare a variable array and then change its size using the ReDim construct.

To implement this source code create a new VB6 program, add a button to the form, double click the button to get into its click event handler method, and add the following code within that method.

  1. Dim mByte() As Byte
  3. Open "C:\" For Binary As #1
  4. Open "C:\" For Binary As #2
  6. ReDim mByte(0 To LOF(1))
  8. Get #1, , mByte()
  9. Put #2, , mByte()
  11. Close #1
  12. Close #2
  14. MsgBox "Done", vbInformation

After running this program and clicking the button you should see a copy of the file created on the C drive with a name of Note: This actually copy's the entire file into memory so you would want to do it in chunks if you were copying a very large file.

Note: The source for this was found at DreamVB which is no longer online.

If you enjoyed this post, subscribe for updates (it's free)

hello sir/madam,i would to

hello sir/madam,i would to ask some help from you about on how to display O.S an specifications of computer and other devices using vb6..
please send me some codes..tanx

Printing in Datagrid.

Hi sir. Could you please help me with the code that I can use to send data in a datagrid to a printer



The contents of (whatever that may be) will be placed into, followed by a message box saying "Done"


Please can some one help me with a logic in VB 6.0 that can copy name of a folder and concartinate it with names of files inside the folder. thanks


So what is the output of that code??