Problem with Folder access
-
Hi, I have a small problem with folder deletion from a VB application. It's a bit long, so bare with me. I have a form that upon its initialization a folder is created using MkDir. When the form unloads, in its Terminate event the folder is being deleted using RmDir. in between, temporary files are written in to the folder, and deleted from it. My problematic scenario is this: 1. the folder is created. 2. files are written. 3. files are deleted. and here is where the problem starts: on one computer (debug computer), the RmDir throws an exception of access denied, because a process is locking the folder, but I ignore this error, and when I load the form again, I ignore the error the MkDir throws, and everything seems to work fine (except for the fact that the folder isn't deleted). on another computer (which also happens to be the QA, and thus really important), again the folder is not deleted (I don't know if there is an error or not - can't debug), but it is also not accessible anymore. Since it is not accessible, when I re-load the form and try to create the folder again, I get an error. The folder is in limbo. when i close the application (and its process dies) the folder is deleted. my two main goals are a) figure out why the computers are behaving differently b) figure out a way to find out what locks the folder, and release the lock. The only workaround we found, was not to create the same folder each time , but that requires a lot of code changes to VB code as well as C code, as well as not prevent accumulation of temporary folders in my system, both of which I would like to avoid. Any help would be amazing. Thanks. :-D P.S. - in case it was not clear - this is VB6 code.
-
Hi, I have a small problem with folder deletion from a VB application. It's a bit long, so bare with me. I have a form that upon its initialization a folder is created using MkDir. When the form unloads, in its Terminate event the folder is being deleted using RmDir. in between, temporary files are written in to the folder, and deleted from it. My problematic scenario is this: 1. the folder is created. 2. files are written. 3. files are deleted. and here is where the problem starts: on one computer (debug computer), the RmDir throws an exception of access denied, because a process is locking the folder, but I ignore this error, and when I load the form again, I ignore the error the MkDir throws, and everything seems to work fine (except for the fact that the folder isn't deleted). on another computer (which also happens to be the QA, and thus really important), again the folder is not deleted (I don't know if there is an error or not - can't debug), but it is also not accessible anymore. Since it is not accessible, when I re-load the form and try to create the folder again, I get an error. The folder is in limbo. when i close the application (and its process dies) the folder is deleted. my two main goals are a) figure out why the computers are behaving differently b) figure out a way to find out what locks the folder, and release the lock. The only workaround we found, was not to create the same folder each time , but that requires a lot of code changes to VB code as well as C code, as well as not prevent accumulation of temporary folders in my system, both of which I would like to avoid. Any help would be amazing. Thanks. :-D P.S. - in case it was not clear - this is VB6 code.
soporificeffect wrote:
the RmDir throws an exception of access denied, because a process is locking the folder, but I ignore this error
Do you have a command prompt open or a DOS-based app running with this folder as the current directory?? A Windows process cannot "lock" the folder itself, only the files in it. If there is a file in that folder that is open, you cannot remove the folder that contains it, be it a DOS or Windows process. Is the folder empty when you try and RmDir it?? There can be no files in it when you do this. Do you have a virus scanner running, indexing service, or something else going on "behind the scenes"?? Disable it and try your app again.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007modified on Tuesday, December 04, 2007 2:11:25 PM
-
soporificeffect wrote:
the RmDir throws an exception of access denied, because a process is locking the folder, but I ignore this error
Do you have a command prompt open or a DOS-based app running with this folder as the current directory?? A Windows process cannot "lock" the folder itself, only the files in it. If there is a file in that folder that is open, you cannot remove the folder that contains it, be it a DOS or Windows process. Is the folder empty when you try and RmDir it?? There can be no files in it when you do this. Do you have a virus scanner running, indexing service, or something else going on "behind the scenes"?? Disable it and try your app again.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007modified on Tuesday, December 04, 2007 2:11:25 PM
I delete all the files before I try to remove the folder. the folder is empty. there are no applications using this folder. I'm not sure what services run in the background, but it is not possible to disable them. All this also does not explain how on the second computer the folder ends up in "Limbo", I can see it in the windows explorer, but I can't access it, it's as if the RmDir hasn't finished running, because the second the app closes the folder is gone