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. Check is file is locked

Check is file is locked

Scheduled Pinned Locked Moved C / C++ / MFC
questionjson
4 Posts 3 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.
  • P Offline
    P Offline
    pranavamhari
    wrote on last edited by
    #1

    hi all, i need to check if a file is in use/locked. (then i have to delete the file if i want.) how can i do it using win32 api? regards Hari Krishnan

    R 1 Reply Last reply
    0
    • P pranavamhari

      hi all, i need to check if a file is in use/locked. (then i have to delete the file if i want.) how can i do it using win32 api? regards Hari Krishnan

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

      If the file exists but you can't open it for exclusive read access, you can safely assume it's locked by another process. Assuming you're using MFC, see CFile for more information. /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

      P 1 Reply Last reply
      0
      • R Ravi Bhavnani

        If the file exists but you can't open it for exclusive read access, you can safely assume it's locked by another process. Assuming you're using MFC, see CFile for more information. /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

        P Offline
        P Offline
        pranavamhari
        wrote on last edited by
        #3

        Hi, thanks, but i don't want to use CFile. After checking i want to delete the file. Is there any win32 way ? I've read now that CreateFile can check this. But is not sure about the arguments. Hari Krishnan

        D 1 Reply Last reply
        0
        • P pranavamhari

          Hi, thanks, but i don't want to use CFile. After checking i want to delete the file. Is there any win32 way ? I've read now that CreateFile can check this. But is not sure about the arguments. Hari Krishnan

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          HFILE hFile = OpenFile(..., OF_SHARE_EXCLUSIVE);
          if (HFILE_ERROR != hFile)
          {
          DeleteFile(...);
          }

          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