Hello everyone! I'm trying to copy folders. I need a progress bar for showing folder copy progress. Can anyone help me?
(NOTE: I'm using Visual Studio 2010 and .NET Framework 4.0)
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dea SaddlerPosted Apr 27, 2011, 7:51 AM
Imports System.IO
Public Class Form1
Dim strSource, strDestination As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnnSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnSource.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
txtSource.Text = FolderBrowserDialog1.SelectedPath
strSource = FolderBrowserDialog1.SelectedPath
End If
End Sub
Private Sub bttnDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnDestination.Click
If FolderBrowserDialog2.ShowDialog() = DialogResult.OK Then
txtDestination.Text = FolderBrowserDialog2.SelectedPath
strDestination = FolderBrowserDialog2.SelectedPath
End If
End Sub
Private Sub bttnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnCopy.Click
Dim count As Integer
Dim i As Integer = Directory.GetFiles(strSource).Length
ProgressBar1.Maximum = i
Dim files() As String = Directory.GetFiles(strSource)
For Each file As String In files
Dim fi As String = Path.GetFileName(file)
My.Computer.FileSystem.CopyFile(file, strDestination & "\" & fi)
ProgressBar1.PerformStep()
count += 1
Next
Dim timeOut As DateTime = Now.AddMilliseconds(1000) 'allow files to be moved
Do
Application.DoEvents()
Loop Until Now > timeOut
If count = i Then
MessageBox.Show("Files copied sucessfully")
End If
End Sub
End Class
Hope this will help you.
FroglegPosted Apr 25, 2011, 3:36 AM