Copy Files with Progressbar.
hi, i need to make a program to copy files from one folder to another
i use this program to copy but the form hangs until the copy is completed even if i use it in background worker.
so can anyone tell me how to use this program in a background worker and also with progressbar
Code:
Public Sub copyFiles(ByVal DirPath As String, ByVal DestPath As String, _
Optional ByVal IncludeSubFolders As Boolean = True)
Dim objFileInfo1 As FileInfo
Dim objDir1 As DirectoryInfo = New DirectoryInfo(DirPath)
Dim objSubFolder1 As DirectoryInfo
'Try
If Directory.Exists(DestPath) = False Then
Directory.CreateDirectory(DestPath)
End If
'add length of each file
For Each objFileInfo1 In objDir1.GetFiles()
'MsgBox(objFileInfo1.Name)
File.Copy(objFileInfo1.FullName, DestPath & "\" & objFileInfo1.Name, True)
'Form1.BackgroundWorker1.ReportProgress(updateSize(Form1.TextBox1.Text, Form1.TextBox2.Text))
Next
'call recursively to get sub folders
'if you don't want this set optional
'parameter to false
If IncludeSubFolders Then
For Each objSubFolder1 In objDir1.GetDirectories()
'MsgBox(getSubfolderName(DirPath, objSubFolder1.FullName))
copyFiles(objSubFolder1.FullName, _
DestPath & "\" & getSubfolderName(DirPath, objSubFolder1.FullName))
'Form1.BackgroundWorker1.ReportProgress(updateSize(Form1.TextBox1.Text, Form1.TextBox2.Text))
Next
End If
'Catch Ex As Exception
'MsgBox(Ex.Message)
'End Try
End Sub