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

Delete Directory not working

P: n/a
Private Sub mnu2Exit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu2Exit.Click

Dim fDir As String = Path.GetDirectoryName(L3Global.VideoFileName)

File.Delete(L3Global.VideoFileName)

' The following is not working - reports directory not empty exception

' Directory.Delete(fDir)

Application.Exit()

End Sub

There is only one file in there. Once the app exits, I see that the
directory is empty. Perhaps the file takes a while to delete or the
application is still using it until it exits. How can I make sure the
directory is also delete.

Thoughts?
--
Anil Gupte
www.keeninc.net
www.icinema.com
Nov 26 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,

Try something like this. Note I am assuming there are only fno sub
directories in the directory you are trying to delete.

Dim di As New IO.DirectoryInfo("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperBound(0) To 0 Step -1
Files(x).Delete()
Next
IO.Directory.Delete("YourPath")

Ken
-------------------------------
"Anil Gupte" wrote:
Private Sub mnu2Exit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu2Exit.Click

Dim fDir As String = Path.GetDirectoryName(L3Global.VideoFileName)

File.Delete(L3Global.VideoFileName)

' The following is not working - reports directory not empty exception

' Directory.Delete(fDir)

Application.Exit()

End Sub

There is only one file in there. Once the app exits, I see that the
directory is empty. Perhaps the file takes a while to delete or the
application is still using it until it exits. How can I make sure the
directory is also delete.

Thoughts?
--
Anil Gupte
www.keeninc.net
www.icinema.com
Nov 26 '06 #2

P: n/a
Interestingly, I did try that, but that gave the exact same results. Except
I did
For Each fileName In fileEntries
filename.delete()
next
something simialr anyway, I erased that chuck of code.

It so happens that the file I am deleting is a Windows Media file, and I can
hear it playing until the applicaiton exists. I can't force users to close
the file before they exit....

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
Hi,

Try something like this. Note I am assuming there are only fno sub
directories in the directory you are trying to delete.

Dim di As New IO.DirectoryInfo("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperBound(0) To 0 Step -1
Files(x).Delete()
Next
IO.Directory.Delete("YourPath")

Ken
-------------------------------
"Anil Gupte" wrote:
>Private Sub mnu2Exit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu2Exit.Click

Dim fDir As String = Path.GetDirectoryName(L3Global.VideoFileName)

File.Delete(L3Global.VideoFileName)

' The following is not working - reports directory not empty exception

' Directory.Delete(fDir)

Application.Exit()

End Sub

There is only one file in there. Once the app exits, I see that the
directory is empty. Perhaps the file takes a while to delete or the
application is still using it until it exits. How can I make sure the
directory is also delete.

Thoughts?
--
Anil Gupte
www.keeninc.net
www.icinema.com

Nov 26 '06 #3

P: n/a
Would this still work if there were directories in the directory?
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
Hi,

Try something like this. Note I am assuming there are only fno sub
directories in the directory you are trying to delete.

Dim di As New IO.DirectoryInfo("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperBound(0) To 0 Step -1
Files(x).Delete()
Next
IO.Directory.Delete("YourPath")

Ken
-------------------------------
"Anil Gupte" wrote:
>Private Sub mnu2Exit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu2Exit.Click

Dim fDir As String = Path.GetDirectoryName(L3Global.VideoFileName)

File.Delete(L3Global.VideoFileName)

' The following is not working - reports directory not empty exception

' Directory.Delete(fDir)

Application.Exit()

End Sub

There is only one file in there. Once the app exits, I see that the
directory is empty. Perhaps the file takes a while to delete or the
application is still using it until it exits. How can I make sure the
directory is also delete.

Thoughts?
--
Anil Gupte
www.keeninc.net
www.icinema.com

Nov 26 '06 #4

P: n/a
You can try to copy the file playing. Then when the program exits, it erases
the temp folder. I don't know if the file.delete/directory.delete command
deletes files in use.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Anil Gupte" <an*******@icinema.comwrote in message
news:OS****************@TK2MSFTNGP02.phx.gbl...
Interestingly, I did try that, but that gave the exact same results. Except
I did
For Each fileName In fileEntries
filename.delete()
next
something simialr anyway, I erased that chuck of code.

It so happens that the file I am deleting is a Windows Media file, and I can
hear it playing until the applicaiton exists. I can't force users to close
the file before they exit....

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
Hi,

Try something like this. Note I am assuming there are only fno sub
directories in the directory you are trying to delete.

Dim di As New IO.DirectoryInfo("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperBound(0) To 0 Step -1
Files(x).Delete()
Next
IO.Directory.Delete("YourPath")

Ken
-------------------------------
"Anil Gupte" wrote:
>Private Sub mnu2Exit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnu2Exit.Click

Dim fDir As String = Path.GetDirectoryName(L3Global.VideoFileName)

File.Delete(L3Global.VideoFileName)

' The following is not working - reports directory not empty exception

' Directory.Delete(fDir)

Application.Exit()

End Sub

There is only one file in there. Once the app exits, I see that the
directory is empty. Perhaps the file takes a while to delete or the
application is still using it until it exits. How can I make sure the
directory is also delete.

Thoughts?
--
Anil Gupte
www.keeninc.net
www.icinema.com


Nov 26 '06 #5

P: n/a
On Sun, 26 Nov 2006 23:15:10 GMT, Ryan S. Thiele wrote:
You can try to copy the file playing. Then when the program exits, it erases
the temp folder. I don't know if the file.delete/directory.delete command
deletes files in use.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Anil Gupte" <an*******@icinema.comwrote in message
news:OS****************@TK2MSFTNGP02.phx.gbl...
Interestingly, I did try that, but that gave the exact same results. Except
I did
For Each fileName In fileEntries
filename.delete()
next
something simialr anyway, I erased that chuck of code.

It so happens that the file I am deleting is a Windows Media file, and I can
hear it playing until the applicaiton exists. I can't force users to close
the file before they exit....
For a fact, from experience, it will NOT delete an in-use file. It should
be throwing an exeption if the OP is checking for that.

//al
Nov 26 '06 #6

P: n/a
Actually this is a temp file. I copy the original, which is inside a zip to
a temp.wmv file. So you say it will not delete a file in use, but it is
deleting it, and I can hear it playing (in fact I hit exit while it is
playing). However, when it gets to the new instruction to delete the
directory it says the directory is not empty and throws an exception with
that message. When the app exits, the file has been deleted.

--
Anil Gupte
www.keeninc.net
www.icinema.com

"al jones" <al**********@shotmail.comwrote in message
news:8e*****************************@40tude.net...
On Sun, 26 Nov 2006 23:15:10 GMT, Ryan S. Thiele wrote:
>You can try to copy the file playing. Then when the program exits, it
erases
the temp folder. I don't know if the file.delete/directory.delete command
deletes files in use.

--
Thiele Enterprises - The Power Is In Your Hands Now!

--
"Anil Gupte" <an*******@icinema.comwrote in message
news:OS****************@TK2MSFTNGP02.phx.gbl...
Interestingly, I did try that, but that gave the exact same results.
Except
I did
For Each fileName In fileEntries
filename.delete()
next
something simialr anyway, I erased that chuck of code.

It so happens that the file I am deleting is a Windows Media file, and I
can
hear it playing until the applicaiton exists. I can't force users to
close
the file before they exit....

For a fact, from experience, it will NOT delete an in-use file. It should
be throwing an exeption if the OP is checking for that.

//al

Nov 27 '06 #7

P: n/a
On Mon, 27 Nov 2006 11:42:13 +0530, Anil Gupte wrote:
Actually this is a temp file. I copy the original, which is inside a zip to
a temp.wmv file. So you say it will not delete a file in use, but it is
deleting it, and I can hear it playing (in fact I hit exit while it is
playing). However, when it gets to the new instruction to delete the
directory it says the directory is not empty and throws an exception with
that message. When the app exits, the file has been deleted.
I know I'll get corrected if I'm wrong, and welcome that, but I'd suggest
that since you're able to delete the file while it's still playing that WMP
(or whatever you're playing it with) already has it completely buffered so
that it's not, in fact, in use.

//al
Nov 27 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.