Im attempting to make a program that will copy files reclusively in VB.NET.
basically I have a function that calculates the total size of every file in the directory and sub directories then goes through all of them and calls the CopyFile function.
this works alright in that my progress bar actually updates while the file is being copied instead of using filenames like I had been. It just seams to be going a lot slower. Five seconds for a 156k file as opposed to bellow three.
Is there a better way?
Clint
basically I have a function that calculates the total size of every file in the directory and sub directories then goes through all of them and calls the CopyFile function.
this works alright in that my progress bar actually updates while the file is being copied instead of using filenames like I had been. It just seams to be going a lot slower. Five seconds for a 156k file as opposed to bellow three.
Is there a better way?
Clint
Code:
Private Function CopyFile(ByVal OldFile As String, ByVal NewFile As String)
Me.FileProgressbar.Value = 0
Dim FS As New FileStream(OldFile, FileMode.Open)
Dim FW As New FileStream(NewFile, FileMode.CreateNew)
Dim Buffer() As Byte
Get the bytes from file to a byte array
ReDim Buffer(FS.Length - 1)
Me.FileProgressbar.Maximum = FS.Length
FS.Read(Buffer, 0, Buffer.Length)
Do your stuff :-)
For i As Int32 = 0 To Buffer.Length - 1
Me.FileProgressbar.Value += 1
FW.WriteByte(Buffer(i))
Me.TotalProgressbar.Value += 1
Next
FS.Close()
FW.Close()
End Function