By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

How can I delete a non empty folder ?

P: n/a
I am using VB.NET 2005.
When I try to delete a folder that has files underneath it, it gave me "the
directory is not empty" error.

f = New IO.DirectoryInfo("C:\myfolder")
If f.Exists Then
f.Delete() --error "the directory is not empty"
End If

How can I delete a folder with files underneath it ? Thank you.
Jan 28 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Jan 28, 11:12*pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2005.
When I try to delete a folder that has files underneath it, it gave me "the
directory is not empty" error.

f = New IO.DirectoryInfo("C:\myfolder")
If f.Exists Then
* * f.Delete() *--error "the directory is not empty"
End If

How can I delete a folder with files underneath it ? Thank you.
I think it's not a problem about your code, it's about the directory.
I think(not sure) you can't delete this directory manually under
Explorer without your app, neither.

I recommend you to see for "hidden" files in your directory which may
be in use by Windows. Then delete all hidden files, try again.
Jan 28 '08 #2

P: n/a

"fniles" <fn****@pfmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>I am using VB.NET 2005.
When I try to delete a folder that has files underneath it, it gave me
"the directory is not empty" error.

f = New IO.DirectoryInfo("C:\myfolder")
If f.Exists Then
f.Delete() --error "the directory is not empty"
End If

How can I delete a folder with files underneath it ? Thank you.

Do as the message says and delete all the files in the folder. If there are
sub-folders you will have to do the same with them.

LS

Jan 28 '08 #3

P: n/a
Use Directory.Delete(folder, true). This override allows for recursion on
non-empty folders, provided you have permission to do so on all files.

"fniles" wrote:
I am using VB.NET 2005.
When I try to delete a folder that has files underneath it, it gave me "the
directory is not empty" error.

f = New IO.DirectoryInfo("C:\myfolder")
If f.Exists Then
f.Delete() --error "the directory is not empty"
End If

How can I delete a folder with files underneath it ? Thank you.
Jan 29 '08 #4

P: n/a
Try using :
My.Computer.FileSystem.DeleteDirectory(......)

There's a number of overloads there that allow various options including
deleting content, showing progress, using recycle bin etc.
"fniles" <fn****@pfmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>I am using VB.NET 2005.
When I try to delete a folder that has files underneath it, it gave me
"the directory is not empty" error.

f = New IO.DirectoryInfo("C:\myfolder")
If f.Exists Then
f.Delete() --error "the directory is not empty"
End If

How can I delete a folder with files underneath it ? Thank you.

Jan 29 '08 #5

P: n/a
If System.IO.Directory.exists(PATH) then _
System.io.directory.delete(PATH, true)

Ref: http://msdn2.microsoft.com/zh-tw/lib...te(VS.80).aspx
Jan 29 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.