Código vb:
Ver original
Imports System.IO Imports System.IO.DirectoryInfo Imports System.IO.Directory Imports Ionic.Zip Imports System Public Class Form1 Private strPath As String Dim txt As String, bol As Boolean Dim a As String = ".zip" Private Sub btnArchivo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArchivo.Click Try With FolderBrowserDialog1 .Reset() .Description = " Seleccionar una carpeta " .SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) .ShowNewFolderButton = False Dim ret As DialogResult = .ShowDialog If ret = Windows.Forms.DialogResult.OK Then 'Dim nFiles As ObjectModel.ReadOnlyCollection(Of String) 'nFiles = My.Computer.FileSystem.GetFiles(.SelectedPath, FileIO.SearchOption.SearchAllSubDirectories) TextBox1.Text = FolderBrowserDialog1.SelectedPath.ToString() End If .Dispose() End With Catch oe As Exception MsgBox(oe.Message, MsgBoxStyle.Critical) End Try End Sub Public Sub Comprimirtxt1() Dim txtFiles = Directory.GetFiles(Me.TextBox1.Text, "*.txt") For Each currentFile As String In txtFiles Using zip As ZipFile = New ZipFile() zip.AddFile(currentFile, "") zip.Save(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(currentFile), System.IO.Path.GetFileNameWithoutExtension(currentFile) + ".zip")) File.Delete(currentFile) End Using Next End Sub Private Sub btnComprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComprimir.Click Comprimirtxt() MessageBox.Show("Accion Finalizada!", "Accion exitosa", MessageBoxButtons.OK) End Sub Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged ProgressBar1.Value = e.ProgressPercentage End Sub Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted MessageBox.Show("Proceso Completado") End Sub Private Sub Proceso() ' PROCESO Dim i As Integer For i = 1 To 100 If Me.BackgroundWorker1.CancellationPending = True Then MsgBox("El proceso se canceló") Exit Sub End If BackgroundWorker1.ReportProgress(i) Threading.Thread.Sleep(500) Next End Sub End Class
Yo se que en BackgroundWorker1_DoWork le debo indicar que hacer pero no se como indicarle que avance segun el archivo comprimido hasta llenar la barra de progreso...
Saludos buen dia!