473,395 Members | 1,978 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,395 software developers and data experts.

Delete Directory not working

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
7 4206
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: da Vinci | last post by:
Greetings, Onwards with the school studying. Working on a program and need to delete a file from a known location on the hard drive but cannot get anything I do to work. I have tried to use...
1
by: zhiwei wang | last post by:
I am new to dealing with the file system using C. And couldnt find anyone in my office to help me out. :( okay here is my questions. If I want to delete a file in a directory other than my...
2
by: Pujo Aji | last post by:
Hello, I would like to create program which delete files using * symbol. I tried to use this code but it is not working: File.Delete(@"d:\example.*");//filename example, directory everthing,...
6
by: gl | last post by:
I'm trying to delete a directory that contains readonly files. Is there any easy way to do this? I get a System.UnauthorizedAccessException when a read only file is encountered. Is there a way to...
0
by: Arjan van den Noort | last post by:
How to delete a directory (with all containing directories and files) with vb.net if the directory contains long paths ? (just like the dos command: RD /S/Q path) What I want is a routine to...
0
by: wolfsbane | last post by:
Alright, here it is I am trying to write a win32 app in VB 2005 to clean up user's profiles. everything works correctly except for the Delete("directory", True) statement. I get a...
5
by: Gordon | last post by:
I'm trying to remove a directory and all its contents from within a script. I wrote a recursive function to take care of it, but when I run it I get random "Directory not empty" error messages. ...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
2
Airslash
by: Airslash | last post by:
Hi, I'm currently working on a function to delete a folder and its files + subfolders. The function currently works for the target folder, but refuses to delete the subfolders and files in the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.