Function horribly slow
- From: Patrick Weidener <pawei_nospom@xxxxxxx>
- Date: Wed, 08 Oct 2008 00:31:08 +0200
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
.
- Follow-Ups:
- Re: Function horribly slow
- From: Karl E. Peterson
- Re: Function horribly slow
- From: Patrick Weidener
- Re: Function horribly slow
- Prev by Date: Re: How to load resorces of a form that is not loaded
- Next by Date: Re: Function horribly slow
- Previous by thread: API URLDownloadToFile or Inet Control
- Next by thread: Re: Function horribly slow
- Index(es):
Loading