How to tell if a file is opened?
-
Is there a good way to tell whether some process has a given file open. I am writing an application that allows the user to open a file in an arbitrary external editor. I start the editor in a spawned process with P_NOWAIT or P_DETACH flags, and want to figure out whether the editor has closed the file. Since the user can arbitrarily choose the editor, I can't make any assumptions about DDE or similar calls to the editor to query the status of the file. The user may close the file in the editor without closing the editor, so I can't simply check whether the given PID has exited. Thus, my question is: given a PID (process id) and a filename (full path), is there a Win32 API method of determining whether the process PID currently has the given file open? Thanks, Jonathan Why couldn't Science, in the long run, serve As well as one's uncleared lunch-table or Mme X en Culottes de Matador? James Merrill
-
Is there a good way to tell whether some process has a given file open. I am writing an application that allows the user to open a file in an arbitrary external editor. I start the editor in a spawned process with P_NOWAIT or P_DETACH flags, and want to figure out whether the editor has closed the file. Since the user can arbitrarily choose the editor, I can't make any assumptions about DDE or similar calls to the editor to query the status of the file. The user may close the file in the editor without closing the editor, so I can't simply check whether the given PID has exited. Thus, my question is: given a PID (process id) and a filename (full path), is there a Win32 API method of determining whether the process PID currently has the given file open? Thanks, Jonathan Why couldn't Science, in the long run, serve As well as one's uncleared lunch-table or Mme X en Culottes de Matador? James Merrill
You can test if a file is open by trying to open it for exclusive access with no sharing. It the file exists but the open fails, another process has opened it. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com
-
You can test if a file is open by trying to open it for exclusive access with no sharing. It the file exists but the open fails, another process has opened it. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com
Cool! Elegant solution. Thanks.