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. checking if a folder exists or not

checking if a folder exists or not

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorial
7 Posts 6 Posters 1 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.
  • S Offline
    S Offline
    sudeep_br
    wrote on last edited by
    #1

    want to check if a folder exists in a computer or not. for example if the path is "c:\DK\Index " i want to check if the folders DK and Index already exists in c drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this. Thank You

    C E H R K 5 Replies Last reply
    0
    • S sudeep_br

      want to check if a folder exists in a computer or not. for example if the path is "c:\DK\Index " i want to check if the folders DK and Index already exists in c drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this. Thank You

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      see _access Cleek | Image Toolkits | Thumbnail maker

      1 Reply Last reply
      0
      • S sudeep_br

        want to check if a folder exists in a computer or not. for example if the path is "c:\DK\Index " i want to check if the folders DK and Index already exists in c drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this. Thank You

        E Offline
        E Offline
        eli15021979
        wrote on last edited by
        #3

        Hi , Try this :

        CFileFind finder;
        CString szPath , szCMD;
        
        szPath = "c:\\DK\\Index";
        // create the directory - if there isn't one allready
        if(!finder.FindFile(szPath))
        {
            szCMD = "mkdir ";
            szCMD += szPath;
            system((LPCTSTR)szCMD);
        }
        

        With best regards, Eli

        S 1 Reply Last reply
        0
        • S sudeep_br

          want to check if a folder exists in a computer or not. for example if the path is "c:\DK\Index " i want to check if the folders DK and Index already exists in c drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this. Thank You

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          WIN32_FIND_DATA m_data; HANDLE hFile; hFile=FindFirstFile("c:\\test",&m_data); if(hFile==INVALID_HANDLE_VALUE) MessageBox("Not Found"); else { MessageBox("ok"); FindClose(hFile); }_**


          **_

          whitesky


          1 Reply Last reply
          0
          • S sudeep_br

            want to check if a folder exists in a computer or not. for example if the path is "c:\DK\Index " i want to check if the folders DK and Index already exists in c drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this. Thank You

            R Offline
            R Offline
            rbid
            wrote on last edited by
            #5

            Another way to do it: Using CFileStatus from MFC..

            CString folderPath = \_T("C:\\\\DK\\\\Index");
            
            CFileStatus status;
            if(!CFile::GetStatus( folderPath, status ) )   // static function
            {
                AfxMessageBox(\_T("Directory does not exist.(\\"") + folderPath + \_T("\\")\\n"),
                              MB\_OK|MB\_ICONINFORMATION);
                ...
            }
            

            The use of _access (posted by Chris Losinger) may be more suitable for your needs. -- **Ricky Marek** (_AKA: rbid_) -- "Things are only impossible until they are not" --- Jean-Luc Picard My articles

            1 Reply Last reply
            0
            • E eli15021979

              Hi , Try this :

              CFileFind finder;
              CString szPath , szCMD;
              
              szPath = "c:\\DK\\Index";
              // create the directory - if there isn't one allready
              if(!finder.FindFile(szPath))
              {
                  szCMD = "mkdir ";
                  szCMD += szPath;
                  system((LPCTSTR)szCMD);
              }
              

              With best regards, Eli

              S Offline
              S Offline
              sudeep_br
              wrote on last edited by
              #6

              Thank you Mr. eli the code given by you is working fine. Thanks to all of you who have responded

              1 Reply Last reply
              0
              • S sudeep_br

                want to check if a folder exists in a computer or not. for example if the path is "c:\DK\Index " i want to check if the folders DK and Index already exists in c drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this. Thank You

                K Offline
                K Offline
                knoxplusplus
                wrote on last edited by
                #7

                Hi !!! If you want xou can use the InetSTL from STLSoft library. There is a function that can check wheather the directory exists or not. You can find it here: http://www.stlsoft.org I hope, I helped you. By. -:KNOX:-

                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