How to? FAST multiple file copy (200+ files)


New member
Jun 11, 2004
Programming Experience
[font=verdana, arial, helvetica]Esteemed Forum Participants and Lurkers:

The only way I have found to copy multiple files is to do a loop on a directory and copy file-by-file with "FileCopy(src, dest)". The "src" and "dest" fields evidently do NOT take wild cards.
[font=verdana, arial, helvetica]
This File-by-file loop to copy is HORRIBLY slow! I have one folder of 166 files to copy. Is there any other FAST way to do it? I even thought about writing a batch file to do a wild card copy, and then calling it from VB.

Thanks for any comments, suggestions, or assistance.


Sep 15, 2004
Programming Experience
I find it odd that you can use to move an entire directory but cant copy it. anyway the code below will copy several hundred files in under a second using loops and a filecopy function. I alos threw the function on a new trhead so the app can keep doing other things.

Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim t As New Thread(AddressOf CopyFiles)


End Sub

Private Sub CopyFiles()

Dim aFiles() As String = Directory.GetFiles("c:\filecopytest", "*.txt")

Dim i As Int32

Dim file As String

Dim apath() As String

Dim path As String

Dim n As Int32

For i = 0 To UBound(aFiles)


'seperate file and path info

apath = aFiles(i).Split("\")

file = apath(UBound(apath))

path = Mid(aFiles(i), 1, aFiles(i).Length - file.Length)

'Debug.WriteLine("Path = " & path)

'Debug.WriteLine("File = " & file)

'copy file using api call

Debug.WriteLine(CopyFile(path & file, "c:\copyto\" & file, -1))


End Sub

Top Bottom