Hi there...
I have some questions on how to optimize copying data.. here is may code...
Dim aUnicode() As Byte
Dim g1 As Integer
Dim g2 As Integer
Dim fname As String
Function Binary_copy(sourcef As String, destf As String) As Long
Dim totalS, chunksize As Long
Dim wrtn As Long, pse, st, et
wrtn = 0
totalS = CreateObject("Scripting.FileSystemObject").GetFile(sourcef).Size
If Int(totalS / 200) > 3000000 Then chunksize = 3000000 Else chunksize = Int(totalS / 200)
g1 = FreeFile: Open sourcef For Binary As #g1
g2 = FreeFile: Open destf For Binary As #g2
st = Timer
Do Until EOF(g1)
If wrtn + chunksize > totalS Then chunksize = totalS - wrtn
If chunksize = 0 Then chunksize = 1
ReDim aUnicode(1 To chunksize)
Get #g1, , aUnicode
Put #g2, , aUnicode
wrtn = wrtn + chunksize
Label1.Caption = Round(wrtn / 1000000, 2) & " MB out of " & Round(totalS / 1000000, 2) & " MB copied: " & Round(wrtn / totalS, 2) * 100 & "% done..."
pse = Timer + 0.001
et = Timer
If (Int(((et - st) * totalS) / wrtn)) - (Int(et - st)) > 60 Then Label2.Caption = Round((Int(((et - st) * totalS) / wrtn) / 60) - (Int(et - st) / 60), 2) & " mins remaining." Else Label2.Caption = Round((Int(((et - st) * totalS) / wrtn)) - (Int(et - st))) & " seconds remaining."
Do Until Timer > pse
DoEvents
Loop
Loop
Close #g1
Close #g2
End Function
Private Sub Command1_Click()
Dim s As String, d As String, fname
fname = "DB_backup.bak"
s = "\\right_eight\F\" & fname
d = "E:\" & fname
Binary_copy s, d
End Sub
Can you please correct me some errors to optimize the copy process thanks...
I want to know too is it possible to multipy the process to make it much faster
example: in the do while loop... can i make a copy process that copies bytes from start of the file and the other process will read start from the end of the file to make it twice faster.
examples: a file has 10bytes the other process will copy the 1-5bytes and the other is 6-10bites simultenously..
sorry for my english.. any help is much appreciated..
thanks...