473,734 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Directory not working

Private Sub mnu2Exit_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles mnu2Exit.Click

Dim fDir As String = Path.GetDirecto ryName(L3Global .VideoFileName)

File.Delete(L3G lobal.VideoFile Name)

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

' Directory.Delet e(fDir)

Application.Exi t()

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 4221
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.DirectoryInf o("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperB ound(0) To 0 Step -1
Files(x).Delete ()
Next
IO.Directory.De lete("YourPath" )

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

Dim fDir As String = Path.GetDirecto ryName(L3Global .VideoFileName)

File.Delete(L3G lobal.VideoFile Name)

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

' Directory.Delet e(fDir)

Application.Exi t()

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**********@d iscussions.micr osoft.comwrote in message
news:4E******** *************** ***********@mic rosoft.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.DirectoryInf o("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperB ound(0) To 0 Step -1
Files(x).Delete ()
Next
IO.Directory.De lete("YourPath" )

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

Dim fDir As String = Path.GetDirecto ryName(L3Global .VideoFileName)

File.Delete(L3 Global.VideoFil eName)

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

' Directory.Delet e(fDir)

Application.Ex it()

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**********@d iscussions.micr osoft.comwrote in message
news:4E******** *************** ***********@mic rosoft.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.DirectoryInf o("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperB ound(0) To 0 Step -1
Files(x).Delete ()
Next
IO.Directory.De lete("YourPath" )

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

Dim fDir As String = Path.GetDirecto ryName(L3Global .VideoFileName)

File.Delete(L3 Global.VideoFil eName)

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

' Directory.Delet e(fDir)

Application.Ex it()

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.delet e command
deletes files in use.

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

--
"Anil Gupte" <an*******@icin ema.comwrote in message
news:OS******** ********@TK2MSF TNGP02.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**********@d iscussions.micr osoft.comwrote in message
news:4E******** *************** ***********@mic rosoft.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.DirectoryInf o("YourPath")
Dim Files() As IO.FileInfo = di.GetFiles
For x As Integer = Files.GetUpperB ound(0) To 0 Step -1
Files(x).Delete ()
Next
IO.Directory.De lete("YourPath" )

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

Dim fDir As String = Path.GetDirecto ryName(L3Global .VideoFileName)

File.Delete(L3 Global.VideoFil eName)

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

' Directory.Delet e(fDir)

Application.Ex it()

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.delet e command
deletes files in use.

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

--
"Anil Gupte" <an*******@icin ema.comwrote in message
news:OS******** ********@TK2MSF TNGP02.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**********@s hotmail.comwrot e in message
news:8e******** *************** ******@40tude.n et...
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.delet e command
deletes files in use.

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

--
"Anil Gupte" <an*******@icin ema.comwrote in message
news:OS******* *********@TK2MS FTNGP02.phx.gbl ...
Interestingl y, 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
8944
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 the remove function that is included with <cstdio> but cannot get it to work properly. My reference book has the following....
1
1955
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 working directory, I would construct a string look like this: str="../../foo/bar/foobar" add use "remove(str);" to delete this file. A lot of my work involves constructing the directory string, so I wonder if this is a common
2
1770
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, it stop here : file not found Any idea? Thanks
6
31743
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 make c# ignore a read only flag, or perhaps set the read only flag for the directory and have it apply to all files? just wondering what the standard work around to this issue was. Thanks
0
1440
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 delete files and folders from a shared folder (accessed by its UNC-notation). That's all ! Some path names can be long (> 200 characters ) and there are some files and folders that can be read-only. The exceptions I get:
0
2952
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 System.IO.DirectoryNotFoundException: Could not find a part of the path. Then it gives me a random file name from the UserProfile\Local Settings\Temporary Internet Files\Content.IE5\SomeRandomFolder. This is absolutley driving me nuts. So I am gonn give you a basic...
5
3553
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. I dropped some code in to echo out the name of the file that's about to be rmdir()ed or unoink()ed (depending if it's a file or a directory) to see if it was choking on a particular subdirectory, but doing that causes all the error messages to...
1
3144
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 their paired "foreign" resx for that language only and installs those resource files in a subdirectory somewhere. I'm trying to create a setup project in visual studio 2008. Ive got my Application Folder set up with my executable. Im now...
2
4937
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 subfolder. When I debugged the code it returned value 1024 n the SHFileOperation function. I have no idea what it means. anyone could tell me why the function is not deleting it's subdirectory?
0
8777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9184
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6033
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.