Du kan finde længden på filen således. Public Sub længdepåfil() Dim A As Long Open "C:\GTA2DEMO.exe" For Input As #1 A = LOF(1) '=12972175 byte Close End Sub
>> kabbak Tak for svaret. Jeg er bare ikke helt tilfreds. Jeg ved stadig ikke, hvordan jeg aflæser status på kopieringen. Hvordan ved jeg hvornår, der kun mangler 25%, eller 200 kb tilbage.
Hvis du bruger VB's indbyggede FileCopy, så har du ingen mulighed for at aflæse progress.
Du kan alternativt lave din egen FileCopy funktion. Her skal du åbne SourceFile og DestFile, og derefter læse/skrive filindholdet i tilpas blokstørrelser. Herved kan du lave Progress på lopieringen.
Jeg er heller ikke særlig stiv til Progresbar, men prøv om du ikke kan bruge dette til noget..!
Private Sub Command1_Click() Dim Counter As Integer Dim Workarea(30000) As String ProgressBar1.Min = LBound(Workarea) ProgressBar1.Max = UBound(Workarea) ProgressBar1.Visible = True
'Set the Progress's Value to Min. ProgressBar1.Value = ProgressBar1.Min
'Loop through the array. For Counter = LBound(Workarea) To UBound(Workarea) 'Set initial values for each item in the array. Workarea(Counter) = "Initial value" & Counter ProgressBar1.Value = Counter Next Counter ' ProgressBar1.Visible = False ProgressBar1.Value = ProgressBar1.Min End Sub
Private Sub Form_Load() ProgressBar1.Align = vbAlignBottom ProgressBar1.Visible = False Command1.Caption = "Initialize array" End Sub
Man er nød til at åbne filen for så at kopiere tegn for tegn
Public Sub Copy(Fra As String, Til As String, ProgressBar As Object) Dim Buffer As String 'buffer used for copying Dim Pointer As Long 'position of pointer in file Dim X As Integer 'used in for...next loop Dim Whole As Integer Dim Part As Integer
If Dir(Til) <> "" Then Kill (Til) 'checks if destination file exists. if it does, delete it
Open Fra For Binary As #1 Open Til For Binary As #2
Whole = LOF(1) \ 20000 'number of whole 20k chunks Part = LOF(1) Mod 20000 'remainder at the end Buffer = String$(20000, 0) 'buffer Pointer = 1 'start at position 1 ProgressBar.Max = LOF(1)
For X = 1 To Whole Get #1, Pointer, Buffer 'get data Put #2, Pointer, Buffer 'put it to destination file Pointer = Pointer + 20000 'put pointer 20k later If Pointer < ProgressBar.Max Then ProgressBar.Value = Pointer Else ProgressBar.Value = ProgressBar.Max 'update progressbar, make sure it doesn't overflow Next X
Buffer = String$(Part, 0) 'copy the last bit Get #1, Pointer, Buffer 'get the remaining bytes at the end Put #2, Pointer, Buffer 'put them ProgressBar.Value = ProgressBar.Max Close
Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS End Type
Declare Function SHFileOperation Lib "shell32.dll" Alias " SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.