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 file is open or not

Check file is open or not

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 5 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.
  • D Offline
    D Offline
    Davitor
    wrote on last edited by
    #1

    Hi All How can i check text file is open or not?

    N S D 3 Replies Last reply
    0
    • D Davitor

      Hi All How can i check text file is open or not?

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      By some other applications?

      nave [OpenedFileFinder] [My Blog]

      1 Reply Last reply
      0
      • D Davitor

        Hi All How can i check text file is open or not?

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        Try and open it with CreateFile[^], specifying 0 (no sharing) for the dwShareMode parameter. If the file is already open, CreateFile will return INVALID_HANDLE_VALUE and GetLastError will return ERROR_SHARING_VIOLATION. The code below will fail, printing the value of ERROR_SHARING_VIOLATION if the file a.a is already open.

        HANDLE f = CreateFile("a.a", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
           if (f == INVALID_HANDLE_VALUE)
           {
              std::cout << GetLastError() << std::endl;
              return 0;
           }

        1 Reply Last reply
        0
        • D Davitor

          Hi All How can i check text file is open or not?

          D Offline
          D Offline
          Divyang Mithaiwala
          wrote on last edited by
          #4

          You may find your answer over here[^].


          Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer

          _ 1 Reply Last reply
          0
          • D Divyang Mithaiwala

            You may find your answer over here[^].


            Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            I don't think that your sample is written in MFC ... but is good to see the solution way.

            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