How to show progress bar during the files or folders deletion

  • Thread starter Thread starter Riky
  • Start date Start date
R

Riky

hi
i have a windows application. I am select the folder or file name
from the folderbrowserdialog box and to delete the folder or file i am
calling the following code.

Public Function DeleteFile(ByVal path As String) As Boolean
'Delete a specified file
Try
If File.Exists(path) = True Then
File.Delete(path)
Return True
End If
Catch ex As Exception
Throw ex
End Try
End Function

Public Function DeleteFolder(ByVal path As String) As Boolean
'Delete a specified folder
Dim objFileInfo As FileInfo
Dim objFolder As DirectoryInfo
Dim objSubFolder As DirectoryInfo
Dim dirInfo As DirectoryInfo = New DirectoryInfo(path)
Try
If Directory.Exists(path) = True Then
objFolder = New DirectoryInfo(path)
For Each objFileInfo In objFolder.GetFiles()
objFileInfo.Delete()
Next
If dirInfo.GetDirectories.Length = 0 Then
Directory.Delete(dirInfo.FullName)
Return True
Else
For Each objSubFolder In
objFolder.GetDirectories()
DeleteFolder(objSubFolder.FullName)
Next
End If
DeleteFolder(objFolder.FullName)
Return True
End If
Catch ex As Exception
Throw ex
End Try
End Function

but i have to show the progress bar during the files or folder
deletion.
so plz tell me what should i do.
 
Hello Riky,

I see 2 options:

1. Show the Windows dialog for deleting the files or to put them into
the recycle bin:

Delete:
My.Computer.FileSystem.DeleteDirectory("C:\ThisPath",
FileIO.UIOption.AllDialogs, FileIO.RecycleOption.DeletePermanently,
FileIO.UICancelOption.DoNothing)

Recycle bin:
My.Computer.FileSystem.DeleteDirectory("C:\ThisPath",
FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin,
FileIO.UICancelOption.DoNothing)


2. Count files, delete them separately and increase the value for your
status dialog.

Best regards,

Martin
 
Back
Top