dustintinsley
Member
- Joined
- Aug 23, 2006
- Messages
- 8
- Programming Experience
- Beginner
Ok, I am new to VB.NET. Have been using VB6 for some time now. I had created some backup software in VB6 that used a faster file copy function then the standard VB file copy. I need help trying to convert this to VB.NET using the .NET file functions. I tthink it could be done using FileStrem and BinaryReader, and ReadChars(), but I just can't figure out how to do it. Any help is appreciated. Here's the VB6 code (sorry for the no comments, I didnt use to comment code):
VB.NET:
Public Sub CopyFile(fSource As String, fDest As String, BufferSize As Integer)
'buffer size is in MB
Dim fLen As Long, fFileSource As Integer, fFileDest As Integer, PackagSize As Long
Dim LastData As Boolean, sTemp As String
fLen = FileLen(fSource)
fFileSource = FreeFile
fFileDest = fFileSource + 1
PackageSize = BufferSize * 1048576
LastData = False
frmLog.pBarFile.Max = fLen
frmLog.pBarFile.Position = 0
Open fSource For Binary Access Read As fFileSource
Open fDest For Binary Access Write As fFileDest
sTemp = ""
Do Until EOF(fFileSource)
If fLen - Loc(fFileSource) <= PackageSize Then
PackageSize = fLen - Loc(fFileSource) + 1
LastData = True
End If
sTemp = Space$(PackageSize)
Get #fFileSource, , sTemp
If LastData = True Then
sTemp = Mid(sTemp, 1, Len(sTemp) - 1)
End If
frmLog.pBarFile.Position = frmLog.pBarFile.Position + Len(sTemp)
Put #fFileDest, , sTemp
DoEvents
Loop
Close #fFileSource, #fFileDest
End Sub