BeeJ
12/1/2011 12:32:00 AM
Different app but still doing file copy.
Need a progress bar.
Need "air" between copy chunks to allow screen to refresh and timers to
run.
Using FileCopy sDPNSrc, sDPNDst hangs my app while the copy is in
progress and there is no progress feedback. I do not want the API that
does a callback. I want to do it chunk by chunk (that all works fine).
Doing a loop Get / Put to do the copy.
This all is fine except that I need to get the file size to copy.
LOF does not handle large files (so I believe).
My GetFileSize routine does not work in this instance because media
player is touching the file. LOF does work and my FileCopyProg does
work using the LOF() size (for my test case is only 10 MBytes).
So how do I get the filesize of the file being touched by media player.
Here is the file size code I am trying.
Both cases fail with hFile = -1&
FILE_SHARE_READ or GENERIC_READ.
This GetFileSize works fine in all other cases.
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
lpSecurityAttributes As SECURITY_ATTRIBUTES, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function pGetFileSizeEx Lib "kernel32" Alias
"GetFileSizeEx" (ByVal hFile As Long, lpFileSize As LARGE_INTEGER) As
Long
Public Function GetFileSize(ByVal sDPName As String) As Variant
' Get the size of a file
On Error GoTo GetFileSizeErr
Dim hFile As Long
Dim lpSA As SECURITY_ATTRIBUTES
Dim lRet As Long
Dim lpLI As LARGE_INTEGER
lpSA.nLength = LenB(lpSA)
' open existing for read
hFile = CreateFile(sDPName, FILE_SHARE_READ, 0&, lpSA,
OPEN_EXISTING, 0&, 0&)
'hFile = CreateFile(sDPName, GENERIC_READ, 0&, lpSA, OPEN_EXISTING,
0&, 0&)
If hFile = -1& Then
GetFileSize = CDec(0)
Else
lRet = pGetFileSizeEx(hFile, lpLI)
GetFileSize = DecLarge(lpLI.LowPart, lpLI.HighPart)
End If
CloseHandle hFile ' API Call
GetFileSizeExit:
Exit Function
GetFileSizeErr:
LogNow "Get File Size " & err.Description, eActionLog
Resume GetFileSizeExit
End Function 'GetFileSize