Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to tell if a file is opened?

How to tell if a file is opened?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasejsontutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jonathan Gilligan
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • J Jonathan Gilligan

      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

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • R Ravi Bhavnani

        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

        J Offline
        J Offline
        Jonathan Gilligan
        wrote on last edited by
        #3

        Cool! Elegant solution. Thanks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups