Windows - check if file/dir is in use
-
Hi, I would like to check if a file or a directory is in use in windows XP. Basically if you open up explorer navigate to some folder, then open another explorer window and try to erase that folder you'll get an error that the folder could not be removed. Unfortunately if you're in some subfolder the delete on parent operation will erase some folders, then hit the problem folder and stop. That's terrible, because you've erased half the stuff before you find out there's a problem. I want to be able to check if anyone's using any of the files/folders, if not then erase them programatically (possibly get a lock so no one can open it while I'm checking the other files). Any help? It must be possible because of programs like FileMon. But I can't get the source code for it.
-
Hi, I would like to check if a file or a directory is in use in windows XP. Basically if you open up explorer navigate to some folder, then open another explorer window and try to erase that folder you'll get an error that the folder could not be removed. Unfortunately if you're in some subfolder the delete on parent operation will erase some folders, then hit the problem folder and stop. That's terrible, because you've erased half the stuff before you find out there's a problem. I want to be able to check if anyone's using any of the files/folders, if not then erase them programatically (possibly get a lock so no one can open it while I'm checking the other files). Any help? It must be possible because of programs like FileMon. But I can't get the source code for it.
There should be an API to detect if there are open handles on a particular file. At least, there is a utility called 'Task Manager Extension' in CodeProject which is able to enumerate through the open handles on a file. Check out http://www.codeproject.com/system/Task_Manager_Extension.asp[^]
Vasudevan Deepak Kumar Personal Homepage Tech Gossips