OffByOne
OffByOne

Reputation: 37

Where in the process is a file open?

I have an application suite that I maintain for Windows platforms. I recently added some code to a shared library to remove a directory after the app is done with it. In one app, the deletion is successful; in the other, I receive a message telling me the file is in use by another process.

After downloading Process Explorer, I learned what I had already expected, that the process holding the folder is the one trying to delete it.

When I google for an answer, all I see is, "You need to download XYZ to find out what process is holding the file, then close that process," where "XYZ" is Unlocker, Process Explorer, etc. I know the process that is holding the file, but if I terminate it, how can it delete the folder?

Does anyone have any idea about how to locate the code that is holding the folder open? Of the tools that are available for finding which processes are using which files, can any be used to find where in the process the folder is open?

Upvotes: 1

Views: 305

Answers (1)

MSalters
MSalters

Reputation: 179917

There is no concept of a "location in the process" where a file is open. E.g. a very common cause of unintentional open files are leaked handles. That means the file is open precisely because there is no location for the file handle in the process anymore.

Upvotes: 1

Related Questions