|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Delete Directory not workingSystem.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? 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 ------------------------------- Show quoteHide quote "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 > > > 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.... Show quoteHide quote "Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message news:4E5218A4-8924-4DFC-9994-7943D815BCE9@microsoft.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 >> >> >> 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" <anil-l***@icinema.com> wrote in message Interestingly, I did try that, but that gave the exact same results. Exceptnews:OSVb%23hYEHHA.2328@TK2MSFTNGP02.phx.gbl... 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.... Show quoteHide quote "Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message news:4E5218A4-8924-4DFC-9994-7943D815BCE9@microsoft.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 >> >> >> On Sun, 26 Nov 2006 23:15:10 GMT, Ryan S. Thiele wrote:
Show quoteHide quote > You can try to copy the file playing. Then when the program exits, it erases For a fact, from experience, it will NOT delete an in-use file. It should> 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" <anil-l***@icinema.com> wrote in message > news:OSVb%23hYEHHA.2328@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.... be throwing an exeption if the OP is checking for that. //al 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. Show quoteHide quote "al jones" <alfredmjo***@shotmail.com> wrote in message news:8er1vt7cnvkr$.a2ar234awy5w$.dlg@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" <anil-l***@icinema.com> wrote in message >> news:OSVb%23hYEHHA.2328@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 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 I know I'll get corrected if I'm wrong, and welcome that, but I'd suggest> 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. 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 Would this still work if there were directories in the directory?
Show quoteHide quote "Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message news:4E5218A4-8924-4DFC-9994-7943D815BCE9@microsoft.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 >> >> >>
Why is this simple addition throwing an overflow exception?
calling math functions at run time Good book for an absolute beginner on VB.net or 2005 with databases Create Serial Number VS 2005 baffled at step 1 How to run and communicate a DOS program file in a VB.NET program? Problem saving txt box with enter key Can someone please translate this to VB.Net WIALib error Opening...Closing Forms |
|||||||||||||||||||||||