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. test if a File exist or not?

test if a File exist or not?

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 6 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.
  • A Offline
    A Offline
    alan top
    wrote on last edited by
    #1

    I'm sorry I meant to say if there is a method that test if a File exist or not? thanks! alantop

    H _ D 4 Replies Last reply
    0
    • A alan top

      I'm sorry I meant to say if there is a method that test if a File exist or not? thanks! alantop

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

      one way

      WIN32_FIND_DATA m_data;
      HANDLE hFile;

      hFile=FindFirstFile(filename,&m_data)

      if(hFile==INVALID_HANDLE_VALUE) //file not found

      J 1 Reply Last reply
      0
      • A alan top

        I'm sorry I meant to say if there is a method that test if a File exist or not? thanks! alantop

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        You can use SHGetFileInfo() The prototype of the function is as follows: DWORD_PTR SHGetFileInfo( LPCTSTR pszPath, DWORD dwFileAttributes, SHFILEINFO *psfi, UINT cbFileInfo, UINT uFlags ); ;-) _AnShUmAn_

        1 Reply Last reply
        0
        • A alan top

          I'm sorry I meant to say if there is a method that test if a File exist or not? thanks! alantop

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

          and PathFileExists

          A 1 Reply Last reply
          0
          • H Hamid Taebi

            one way

            WIN32_FIND_DATA m_data;
            HANDLE hFile;

            hFile=FindFirstFile(filename,&m_data)

            if(hFile==INVALID_HANDLE_VALUE) //file not found

            J Offline
            J Offline
            Joe Woodbury
            wrote on last edited by
            #5

            Make sure you close the handle if the file is found. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

            H 1 Reply Last reply
            0
            • J Joe Woodbury

              Make sure you close the handle if the file is found. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

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

              sure and thank you use

              FindClose(hFile);

              1 Reply Last reply
              0
              • H Hamid Taebi

                and PathFileExists

                A Offline
                A Offline
                Andy Rama
                wrote on last edited by
                #7

                Hi, When I use "PathFileExists()" in my MFC code, it is giving me Linking error as follows, Linking... aDlg.obj : error LNK2001: unresolved external symbol __imp__PathFileExistsA@4 Debug/a.exe : fatal error LNK1120: 1 unresolved externals Is ther any Library/ Header File for it? Best Regards, Aniket

                H 1 Reply Last reply
                0
                • A Andy Rama

                  Hi, When I use "PathFileExists()" in my MFC code, it is giving me Linking error as follows, Linking... aDlg.obj : error LNK2001: unresolved external symbol __imp__PathFileExistsA@4 Debug/a.exe : fatal error LNK1120: 1 unresolved externals Is ther any Library/ Header File for it? Best Regards, Aniket

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

                  #include shlwapi.h
                  and to your project
                  import shlwapi.lib

                  A 1 Reply Last reply
                  0
                  • H Hamid Taebi

                    #include shlwapi.h
                    and to your project
                    import shlwapi.lib

                    A Offline
                    A Offline
                    Andy Rama
                    wrote on last edited by
                    #9

                    Hi, Thanks for your solution. Now PathFileExists" is working. Aniket

                    1 Reply Last reply
                    0
                    • A alan top

                      I'm sorry I meant to say if there is a method that test if a File exist or not? thanks! alantop

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

                      _access(..., 0) is one way.


                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                      "We will be known forever by the tracks we leave." - Native American Proverb

                      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