473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to show progress bar during the files or folders deletion

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.

Mar 29 '07 #1
1 5926
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:\ThisPat h",
FileIO.UIOption.AllDialogs, FileIO.RecycleOption.DeletePermanently,
FileIO.UICancelOption.DoNothing)

Recycle bin:
My.Computer.FileSystem.DeleteDirectory("C:\ThisPat h",
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

Riky wrote:
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.
Mar 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Raed Sawalha | last post by:
Dear, I have windows form , the form is using a class to do all tasks needed like this private void btnProcess_Click(object sender, System.EventArgs e) { btnProcess.Enabled = false;...
7
by: Steve Kallal | last post by:
I have seen this subject tossed around in this forum before. But in my case I need a simple solution. I do NOT need to show progress in terms on percentage complete. But rather I need to show a...
10
by: Dan | last post by:
Hi - I'm about a week into learning VB.NET, and I'm finding I can't delete any of the VB.NET directory structures that contain my test projects I've been trying to create. I've never seen this...
3
by: Tim Satterwhite | last post by:
Hi All, I think this is a thorny problem, and I'm hoping you can help. I've not found this exact issue described anywhere yet. I have a stored procedure that calls BULK INSERT on a set of...
6
by: pankajprakash | last post by:
hi, i have a windows form and there is a text box to select the file of folder to delete. i need a progress bar during the file of folder deletion.
0
by: remya1000 | last post by:
by using FTP i can send files to server using vb.net. if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by...
2
by: mcw.willart | last post by:
Hi, I use a backgroundworker to get the total size of a homeshare (as it is a bit time-consuming). Wat i would like to do, is show the progress, but at start i don't know how much files/folders...
2
by: Jorgen Bodde | last post by:
Hi all, I want to make a small batch copy tool that scans for certain files, and copies them to a specified directory. Since the files are huge (AVI / DIVX) typical 300 to 700 Mb, I want to...
6
by: kimiraikkonen | last post by:
Hi, I use system.io.file class to copy files but i have a difficulty about implementing a basic / XP-like progress bar indicator during copying process. My code is this with no progress bar,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.