Results 1 to 4 of 4

Thread: Copy a file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Hello!

    Does anyone know how to copy a file with progress indicator (percent, bytes complete...)?

    Zvonko
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986

    sure...

    Sure you can.
    progressBar.Max = FileLen(MYFILE)
    MYCHUNK = 500
    Take chunks of a file, say 500 Bytes at a time, Set the ProgressBar.Value = ProgressBar.Value + MYCHUNK
    and then write that chunk to antoher file
    Put it in a loop and you're ready.

    If you want the code just reply, I'm in hurry



    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Guest

    Lightbulb

    Try this. Make a Form with a CommandButton, CommonDialog, Label and ProgressBar and put the following code into the Form.

    Code:
    Private Sub Command1_Click()
    
        Dim Source As String
        Dim Dest As String
        Dim Data As String
        Dim TransferRate As Integer
        
        CommonDialog1.CancelError = True
        CommonDialog1.Filter = "All Files|*.*"
        CommonDialog1.ShowOpen
        
        If Err <> 32755 Then
        
            Source = CommonDialog1.filename
            Dest = Source & " - Copy 2"
    
            Open Source For Binary As #1
            Open Dest For Binary As #2
            
            ProgressBar1.Max = FileLen(Source)
            TransferRate = 1024
            
            Do Until LOF(1) = Loc(1) Or EOF(1)
                Data = ""
                If LOF(1) - Loc(1) < ChunkSize Then
                    Data = String(LOF(1) - Loc(1), 0)
                Else
                    Data = String(ChunkSize, 0)
                End If
                Get #1, , Data
                Put #2, , Data
                
                Label1.Caption = Loc(1) & " bytes out of " & LOF(1) & " transfered"
                If ProgressBar1.Value + TransferRate > FileLen(Source) Then Exit Do
                ProgressBar1.Value = ProgressBar1.Value + TransferRate
                
            Loop
            
        End If
        
    End Sub
    you will be asked to search for the file in the CommonDialog. When you find it, it will copy it as yourfilename - Copy2. When it's copying, it will show the status with a Label and the ProgressBar.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Thanks, guys!
    You're sooooo gooood!!!
    I don't know what would I do without you...
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width