Function horribly slow



Can anyone tell me why this function is so horribly slow (on some PCs)???

Public Function FileForceCopy(ByVal uSource As String, ByVal uDestination As String) As Boolean
On Error GoTo ErrHandler

Dim lSourceLen&
Dim iSF%
Dim iDF%
Dim sChunk As String
Dim iBytesToGet%
Dim lBytesCopied&

Debug.Print uSource
Debug.Assert FileExists(uSource)

'/* Get source file length */
lSourceLen = FileLen(uSource)

'/* Open both files */
iSF = FreeFile()

'/* We MUST open a file after calling FreeFile(), else the next FreeFile will be the same number */
Open uSource For Binary Shared As #iSF

'/* Only know we can call the next FreeFile() */
iDF = FreeFile()

Debug.Print uDestination
TryKill uDestination

If FileExists(uDestination) Then
Debug.Print "Source: " & uSource
Debug.Print "Destination: " & uDestination
Debug.Assert False
Exit Function
End If

Debug.Print uDestination

Open uDestination For Binary As #iDF

'How many bytes to get each time
iBytesToGet = 4096 '4kb
lBytesCopied = 0

'Keep copying until finishing all bytes
Do While lBytesCopied < lSourceLen
'Check how many bytes left
If iBytesToGet < (lSourceLen - lBytesCopied) Then
'Copy 4 KBytes
sChunk = Space(iBytesToGet)
Get #iSF, , sChunk
Else
'Copy the rest
sChunk = Space(lSourceLen - lBytesCopied)
Get #iSF, , sChunk
End If
lBytesCopied = lBytesCopied + Len(sChunk)

'Put data in destination file
Put #iDF, , sChunk
Loop

Close #iSF
Close #iDF

FileForceCopy = True

Exit Function
ErrHandler:
Debug.Print Err.Description
Debug.Assert FileExists(uSource)
'Debug.Print Len(uSource)
Debug.Print uDestination
Debug.Print uSource
Debug.Assert False
Call WriteLog("#FileForceCopy: " & Err.Description & ", err.number: " & Err.Number & ", Params: '" & "" & "'")
End Function
.


Loading