PDA

Click to See Complete Forum and Search --> : CopyFile API - how to monitor process


Ray-TFR
Feb 28th, 2001, 09:21 AM
I am using the copyfile API to move large files (>1 Gb) on a network. The API works but due to network traffic and such, it can take from minutes to hours to complete.
I am wondering if there is a way of monitoring the copy process so that I can tell how far along the copy is ?

Thanks,

Jhd.Honza
Aug 7th, 2004, 04:07 PM
Use CopyFileEx, but W9x/ME not supported.
AllApi sample:

'in a form (Form1)
Private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long
'set the graphics mode to persistent
Me.AutoRedraw = True
'print some text
Me.Print "Click the form to abort the filecopy"
'show the form
Me.Show
'start copying
Ret = CopyFileEx("c:\verybigfile.ext", "c:\copy.ext", AddressOf CopyProgressRoutine, ByVal 0&, bCancel, COPY_FILE_RESTARTABLE)
'show some text
Me.Print "Filecopy completed " + IIf(Ret = 0, "(ERROR/ABORTED)", "successfully")
End Sub
Private Sub Form_Click()
'cancel filecopy
bCancel = 1
End Sub
'in a module
Public Const PROGRESS_CANCEL = 1
Public Const PROGRESS_CONTINUE = 0
Public Const PROGRESS_QUIET = 3
Public Const PROGRESS_STOP = 2
Public Const COPY_FILE_FAIL_IF_EXISTS = &H1
Public Const COPY_FILE_RESTARTABLE = &H2
Public Declare Function CopyFileEx Lib "kernel32.dll" Alias "CopyFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, ByRef pbCancel As Long, ByVal dwCopyFlags As Long) As Long
Public bCancel As Long
Public Function CopyProgressRoutine(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long, ByVal lpData As Long) As Long
'adjust the caption
Form1.Caption = CStr(Int((TotalBytesTransferred * 10000) / (TotalFileSize * 10000) * 100)) + "% complete..."
'allow user input
DoEvents
'continue filecopy
CopyProgressRoutine = PROGRESS_CONTINUE
End Function

autodebug
Aug 7th, 2004, 07:16 PM
Please try SHFileOperation API.

ice_531
Aug 7th, 2004, 11:44 PM
Why do you people continue to respond to posts over 3 years old?!

Do you think it matters at this point :rolleyes:


ice
:wave:

Jhd.Honza
Aug 8th, 2004, 04:59 AM
Yep, :bigyello:
Of course I don't think Ray-TFR still waits for answer...

Though it can help users which have the same troubles today or later and are looking for the solution.

How do you think I've got to 3 years old thread? :p

PS: As you see, autodebug suggested using SHFileOperation, which works even under Win95, so I also have something new learned.

ice_531
Aug 8th, 2004, 11:12 AM
Well, if you want things users will be able to find you should probably post in the FAQS that is stickied. MAYBE people will look @ the faqs before they post a question or search the forums... ;)