Description:
This function is to copy a file via many small packets, like the real copy functions do.
originally posted on dotnet-snippets.com
This function is to copy a file via many small packets, like the real copy functions do.
Code
Imports System.IO
Public Function CopyFile(ByVal Source As String, ByVal Target As String, Optional ByVal BufferSize As Long = 51200) As Boolean
Try
Dim SourceFileStream As New FileStream(Source, FileMode.Open)
Dim TargetFileStream As New FileStream(Target, FileMode.Create)
Dim Data(BufferSize) As Byte
Dim Buffer As Long = 0
Dim BufferCount As Long = 0
Dim FileSize As Long = SourceFileStream.Length
Do
If BufferCount >= FileSize - BufferSize Then
ReDim Data(FileSize - BufferCount)
Buffer = SourceFileStream.Read(Data, 0, FileSize - BufferCount)
TargetFileStream.Write(Data, 0, Buffer)
Exit Do
End If
Buffer = SourceFileStream.Read(Data, 0, BufferSize)
TargetFileStream.Write(Data, 0, BufferSize)
BufferCount += Buffer
Loop
SourceFileStream.Close()
TargetFileStream.Close()
Catch
Return False
End Try
End Functionoriginally posted on dotnet-snippets.com
[img]http://i685.photobucket.com/albums/vv215/blackpearl4/THANKS.gif[/img]
If You Like this tutorial, please check out my other tutorials by clicking ==> H3R3
PHP & .NET Contributor.

