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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. checking to see if a folder exists

checking to see if a folder exists

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 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.
  • N Offline
    N Offline
    ns
    wrote on last edited by
    #1

    If the user specifies a folder and I need to make sure there is such a folder, how do I check its existence in code? Appreciate your help, ns

    R H P A 4 Replies Last reply
    0
    • N ns

      If the user specifies a folder and I need to make sure there is such a folder, how do I check its existence in code? Appreciate your help, ns

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      I use CreateDirectory(path). if it fails with error 183, it already exists. The only draw back is that if you need to check with them if you want to create it, you already have. Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

      1 Reply Last reply
      0
      • N ns

        If the user specifies a folder and I need to make sure there is such a folder, how do I check its existence in code? Appreciate your help, ns

        H Offline
        H Offline
        HENDRIK R
        wrote on last edited by
        #3

        A call to FindFirstFileEx (also suitable for folders) returns an error code when the specified file doesn't exist - so you can easily check the folder's validity.

        N 1 Reply Last reply
        0
        • H HENDRIK R

          A call to FindFirstFileEx (also suitable for folders) returns an error code when the specified file doesn't exist - so you can easily check the folder's validity.

          N Offline
          N Offline
          ns
          wrote on last edited by
          #4

          Thanks - I will try that Appreciate your help, ns

          1 Reply Last reply
          0
          • N ns

            If the user specifies a folder and I need to make sure there is such a folder, how do I check its existence in code? Appreciate your help, ns

            P Offline
            P Offline
            pete mcquain
            wrote on last edited by
            #5

            ns wrote: how do I check its existence in code? I would do ::GetFileAttributesEx(strFolderPath, GetFileExInfoStandard, NULL) and check the return value and/or check ::GetLastError() for a return of 2 ("System cannot find the file specified") -pete

            1 Reply Last reply
            0
            • N ns

              If the user specifies a folder and I need to make sure there is such a folder, how do I check its existence in code? Appreciate your help, ns

              A Offline
              A Offline
              Abin
              wrote on last edited by
              #6

              http://www.codeproject.com/file/CFileManip.asp[^] int nRes = CFileManip::Existence(_T("c:\\somepath\\somefolder")); if (nRes == CFileManip::FM_DIRECTORY) { // this is an existing folder } else if (nRes == CFileManip::FM_FILE) { // this is an existing file } else { // the specified target does not exist }

              N 1 Reply Last reply
              0
              • A Abin

                http://www.codeproject.com/file/CFileManip.asp[^] int nRes = CFileManip::Existence(_T("c:\\somepath\\somefolder")); if (nRes == CFileManip::FM_DIRECTORY) { // this is an existing folder } else if (nRes == CFileManip::FM_FILE) { // this is an existing file } else { // the specified target does not exist }

                N Offline
                N Offline
                ns
                wrote on last edited by
                #7

                Thank you for yet another workable suggestion. I hadnt explored the file category at CP...:) Appreciate your help, ns

                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