COPIAR ARQUIVO COM BARRA DE PROGRESSO

FROSTYNHO 24/01/2014 00:36:29
#433477
Estou copiando um arquivo de 1GB através do File.Copy porém preciso exibir o progresso, pois a aplicação trava até terminar de copiar, alguém sabe como posso fazer isso? primeira vez que tento fazer isso...
GGERMINIANI 24/01/2014 09:10:45
#433490
FROSTYNHO,
Bom dia.

Veja se o post do Marcoratti lhe ajuda...

http://www.macoratti.net/vb_cabp.htm

Abs
CRACKER 03/03/2014 20:28:06
#435483
Resposta escolhida
Sendo que no Form tenho duas progressbar (a pgrFileCopy para mostrar o progresso do ficheiro actual e a pgrTotalCopy para mostrar o progresso do total de ficheiros), e uma label (lblAcopiar para mostrar o nome do ficheiro que está a ser copiado)


  Public Class frmCopy
Dim sPath As String = [Ô]C:\Pasta_Origem\[Ô]
Dim lPath As String = [Ô]C:\Pasta_Destino\[Ô]


Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cpyFiles()
End Sub

Private Delegate Function CopyProgressRoutine(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32

Private Declare Auto Function CopyFileEx Lib [Ô]kernel32.dll[Ô] (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As CopyProgressRoutine, ByVal lpData As Int32, ByVal lpBool As Int32, ByVal dwCopyFlags As Int32) As Int32

Private Function CopyProgress(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
pgrFileCopy.Value = Convert.ToInt32(totalBytesTransferred / totalFileSize * 100)
End Function

Private Sub cpyFiles()
Dim cpr As New CopyProgressRoutine(AddressOf CopyProgress)
Dim allfiles() As String = IO.Directory.GetFiles(sPath)
Dim filesCopyed As Integer = 0
pgrTotalCopy.Maximum = allfiles.Length - 1
For Each file As String In allfiles
Dim fileName() As String = file.Split([Ô]\[Ô])
lblAcopiar.Text = [Ô]A copiar: [Ô] & fileName(fileName.Length - 1)
CopyFileEx(file, lPath & fileName(fileName.Length - 1), cpr, 0, 0, 0)
filesCopyed += 1
pgrTotalCopy.Value = filesCopyed
Next
End Sub
End Class
CRACKER 03/03/2014 20:31:36
#435484
   Dim pb As New ProgressBar
[ô]copia todos os arquivos do diretório
Dim DirectorioFont As String = [Ô]Pasta a copiar <C:\pasta>[Ô]
Dim DirectorioDestino As String = [Ô]Pasta de destino <C:
ovapasta>[Ô]
Dim ListaDeFiles() = My.Computer.FileSystem.GetFiles(DirectorioFont, _
FileIO.SearchOption.SearchAllSubDirectories, [Ô]*.*[Ô]).ToArray

For i = 0 To ListaDeFiles.Length - 1
Dim file = ListaDeFiles(i)
[ô]Aqui poes o codigo todo de copiar, visto que cada file será o ficheiros,
[ô]Da pasta raiz e das subdirectorias

[ô]No fim poes a progressbar a trabalhar
pb.Value = (i / ListaDeFiles.Length - 1) * 100
Next
Tópico encerrado , respostas não são mais permitidas