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

Webtest

New member
Joined
Jun 11, 2004
Messages
2
Programming Experience
Beginner
[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]
[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.
[/font]
 

talentrio

Member
Joined
Sep 15, 2004
Messages
7
Programming Experience
10+
I find it odd that you can use system.io.directory 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)

t.Start()

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)

'Debug.WriteLine(aFiles(i))

'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))

Next

End Sub

 
Top Bottom