| This routine will copy a file while providing a means to support a percent gauge.Error support is provided. src = Source file name (including path if necessary) dst = Destination file name (including path if necessary) Returns:The function returns the size of the original file on success, 0 on failure. Assumes: The PercentDone may be a Label, or a ProgressBar, or your own custom design. The example has commented code for a Label named PercentDone. Otherwise, you may call your custom routine to display the progress at that point. Side Effects: If the destination file already exists, a message box will prompt the user. Function CopyFile (src As String, dst As String) As Single Static Buf$ Dim BTest!, FSize! Dim Chunk%, F1%, F2% Const BUFSIZE = 2048 'A larger BUFSIZE is best, but do not attempt to exceed 64 K (60000 would be fine) If Dir(src) = "" Then MsgBox "File not found" Exit Function End If If Len(Dir(dst)) Then If MsgBox(UCase(dst) & Chr(13) & Chr(10) & "File exists. Overwrite?", 4) = 7 Then Exit Function Kill dst End If On Error Goto FileCopyError F1 = FreeFile Open src For Binary As F1 F2 = FreeFile Open dst For Binary As F2 FSize = LOF(F1) BTest = FSize - LOF(F2) Do If BTest < BUFSIZE Then Chunk = BTest Else Chunk = BUFSIZE End If Buf = String(Chunk, " ") Get F1, , Buf Put F2, , Buf BTest = FSize - LOF(F2) ' __Call percent display here__ 'PercentDone.Caption = ( 100 - Int(100 * BTest/FSize) ) 'PercentDone.Refresh Loop Until BTest = 0 Close F1 Close F2 CopyFile = FSize Exit Function FileCopyError: MsgBox "Copy Error!" Close F1 Close F2 End Function |
CopyFile |
Express News India | Freelance ecommerce web development India