Hello!
Does anyone know how to copy a file with progress indicator (percent, bytes complete...)?
Zvonko
Printable View
Hello!
Does anyone know how to copy a file with progress indicator (percent, bytes complete...)?
Zvonko
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
:)
Try this. Make a Form with a CommandButton, CommonDialog, Label and ProgressBar and put the following code into the Form.
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.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
Thanks, guys!
You're sooooo gooood!!!
I don't know what would I do without you... ;)