How to show progress bar during the files or folders deletion

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.
 
M

Martin H.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top