USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Arquivos/Diretórios)

Título da Dica:  Copiando arquivos e exibindo o progresso
Postada em 26/10/2003 por ^HEAVY-METAL^            
Function CopyFile (src As String, dst As String) As Single
Static Buf$
Dim BTest!, FSize!
Dim Chunk%, F1%, F2%

Const BUFSIZE = 1024

'This routine will copy a file While providing a means
'To support a percent gauge.  Ex. your display routine
'Is called "PercentDone" And accepts the values 0-100.
'Error support Is provided.
'
'A larger BUFSIZE Is best, but Do Not attempt To exceed
'64 K (60000 would be fine)
'
'The size of the copied file Is returned On success
'0 Is returned On failure

   If Dir(src) = "" Then MsgBox "File not found": Exit Function
   If Len(Dir(dst)) Then
      If MsgBox(UCase(dst) & Chr(13) & Chr(10) & "File exists. Overwrite?", 4) <> 6 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 ( 100 - Int(100 * BTest/FSize) )
   Loop Until BTest = 0
   Close F1
   Close F2
   CopyFile = FSize
   Exit Function

FileCopyError:
   MsgBox "Copy Error!"
   Close F1
   Close F2
   Exit Function
End Function

'For usage
'You would use it as:
ProgressBar1.Value = CopyFile (Which_File, To_Where)

T+,

   Manuel
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página