[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

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


7 Answers

ralph

12/1/2011 2:14:00 AM

0

On Wed, 30 Nov 2011 16:31:34 -0800, BeeJ <nospam@spamnot.com> wrote:

>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.

lol, here we go again. I should know better by now, but I just have to
ask - Why not?

CopyFileEx() is provided for exactly that reason. One call. One
helper. Bang! We're done.

>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).
>

VB6 has problems with any number bigger than a Long. Is that the
issue? Define "large". >2gig? >4gig? You can increase the scale using
a Currency. This has been hashed out a zillion times. Research the
Web.

Why not just read and write the file chunk by chunk, till there ain't
no more chunks?

If you want to report progress as a percent then take an average size,
change your scale around 75-80%. No one pays much attention to those
numbers anyway.
Has it started?
Does this look like it is going to take awhile?
(Translation. Time to get a cup of coffee, or check EMail?)
Are we done yet?

Must be something else to the story. There usually is.

-ralph

Jimekus

12/1/2011 2:15:00 AM

0

On Dec 1, 1:31 pm, BeeJ <nos...@spamnot.com> wrote:
>So how do I get the filesize of the file being touched by media player.

Maybe this can help. Volume Shadow Copy Service 7.2 SDK

(nobody)

12/1/2011 7:31:00 PM

0

"BeeJ" <nospam@spamnot.com> wrote in message
news:jb6ht8$8bl$1@speranza.aioe.org...
> Doing a loop Get / Put to do the copy.

If you open the file "For Binary", you will get errors once you reach the
2GB limit. You will need to do it the API way regardless.


(nobody)

12/1/2011 7:45:00 PM

0

"Nobody" <nobody@nobody.com> wrote in message
news:jb8km9$1j7$1@speranza.aioe.org...
> "BeeJ" <nospam@spamnot.com> wrote in message
> news:jb6ht8$8bl$1@speranza.aioe.org...
>> Doing a loop Get / Put to do the copy.
>
> If you open the file "For Binary", you will get errors once you reach the
> 2GB limit. You will need to do it the API way regardless.

Code to reproduce the problem:

Option Explicit

Private Sub Form_Load()
Dim f As Integer
Dim FileContents(0 To 8191) As Byte
Dim i As Long

f = FreeFile
Open "PathToBigFile" For Binary Access Read Shared As f
For i = 1 To 1000000
Get f, , FileContents
Next
Close f
End Sub

The file needs to be slightly larger than 2 GB. You will get error 63: Bad
record number, when "i" reaches 262144.

262144 * 8192(Buffer size) = 2,147,483,648, or 2 GB exactly.


BeeJ

12/3/2011 2:13:00 AM

0

I hae already incorporated the API verison to handle large files and
added the date / attribute fixes within the copy sub.
Thanks for you feedback.


BeeJ

12/3/2011 2:17:00 AM

0

I like to use the smaller gears. Educational and fun.
I like to watch the gears turn.


BeeJ

12/3/2011 2:18:00 AM

0

Jimekus presented the following explanation :
> On Dec 1, 1:31 pm, BeeJ <nos...@spamnot.com> wrote:
>> So how do I get the filesize of the file being touched by media player.
>
> Maybe this can help. Volume Shadow Copy Service 7.2 SDK

Not sure what that is all about but sounds like so high level thingy
that I would not use.