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. traverse a directory and list all file names?

traverse a directory and list all file names?

Scheduled Pinned Locked Moved C / C++ / MFC
question
13 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.
  • G Offline
    G Offline
    George_George
    wrote on last edited by
    #1

    Hello everyone, Are there any samples to traverse a directory and list all the file names? Written in C. thanks in advance, George

    _ H O 3 Replies Last reply
    0
    • G George_George

      Hello everyone, Are there any samples to traverse a directory and list all the file names? Written in C. thanks in advance, George

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

      George_George wrote:

      list all the file names

      You can use these API's: FindFirstFile() FindNextFile()

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      G 1 Reply Last reply
      0
      • G George_George

        Hello everyone, Are there any samples to traverse a directory and list all the file names? Written in C. thanks in advance, George

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

        See WIN32_FIND_DATA find; HANDLE handle=FindFirstFile("*.*",&find); while(FindNextFile(handle,&find)!=0) m_List2.AddString(find.cFileName);//m_List2 is CListBox FindClose(handle);

        _**


        **_

        WhiteSky


        G 1 Reply Last reply
        0
        • G George_George

          Hello everyone, Are there any samples to traverse a directory and list all the file names? Written in C. thanks in advance, George

          O Offline
          O Offline
          ovidiucucu
          wrote on last edited by
          #4

          You can take a look at THIS FAQ[^]

          Ovidiu Cucu Microsoft MVP - Visual C++

          G 1 Reply Last reply
          0
          • _ _AnsHUMAN_

            George_George wrote:

            list all the file names

            You can use these API's: FindFirstFile() FindNextFile()

            Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

            G Offline
            G Offline
            George_George
            wrote on last edited by
            #5

            Thank you _AnShUmAn_! Are they C/C++ standard or Microsoft specific things? I want to use C/C++ standard API in my application. regards, George

            1 Reply Last reply
            0
            • H Hamid Taebi

              See WIN32_FIND_DATA find; HANDLE handle=FindFirstFile("*.*",&find); while(FindNextFile(handle,&find)!=0) m_List2.AddString(find.cFileName);//m_List2 is CListBox FindClose(handle);

              _**


              **_

              WhiteSky


              G Offline
              G Offline
              George_George
              wrote on last edited by
              #6

              Hi WhiteSky, I find that there are some Microsoft specific things, like WIN32_FIND_DATA. Are there any API/structures which are standard C/C++? regards, George

              1 Reply Last reply
              0
              • O ovidiucucu

                You can take a look at THIS FAQ[^]

                Ovidiu Cucu Microsoft MVP - Visual C++

                G Offline
                G Offline
                George_George
                wrote on last edited by
                #7

                Hi Ovidiu, The sample is very useful. Are there any non-Microsoft specific API/data structure samples? (I mean using pure C/C++ standard API/data structure.) regards, George

                S 1 Reply Last reply
                0
                • G George_George

                  Hi Ovidiu, The sample is very useful. Are there any non-Microsoft specific API/data structure samples? (I mean using pure C/C++ standard API/data structure.) regards, George

                  S Offline
                  S Offline
                  S Douglas
                  wrote on last edited by
                  #8

                  George_George wrote:

                  Are there any non-Microsoft specific API/data structure samples? (I mean using pure C/C++ standard API/data structure.)

                  No file systems are platform specific.


                  I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                  G 1 Reply Last reply
                  0
                  • S S Douglas

                    George_George wrote:

                    Are there any non-Microsoft specific API/data structure samples? (I mean using pure C/C++ standard API/data structure.)

                    No file systems are platform specific.


                    I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                    G Offline
                    G Offline
                    George_George
                    wrote on last edited by
                    #9

                    Confused. All file system should be platform specific, on Window there are special file format, and on Linux, there are others. regards, George

                    S 1 Reply Last reply
                    0
                    • G George_George

                      Confused. All file system should be platform specific, on Window there are special file format, and on Linux, there are others. regards, George

                      S Offline
                      S Offline
                      S Douglas
                      wrote on last edited by
                      #10

                      George_George wrote:

                      All file system should be platform specific, on Window there are special file format, and on Linux, there are others

                      Yup, that's why there isn’t a single ANSI C++ method for accessing the files on the file system. Not to mention, *Nix and Windows treat directory structures differently. Simply '\' is the directory delimiter for Windows & '/" is the delimiter on *Nix (this is a high level difference, but everything adds up). If you want something that isn’t platform specific (as your posts indicated) your stuck with Java (I wonder how far along MONO is) or writing two separate classes and figure out which platform your on at compile time.


                      I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                      G 1 Reply Last reply
                      0
                      • S S Douglas

                        George_George wrote:

                        All file system should be platform specific, on Window there are special file format, and on Linux, there are others

                        Yup, that's why there isn’t a single ANSI C++ method for accessing the files on the file system. Not to mention, *Nix and Windows treat directory structures differently. Simply '\' is the directory delimiter for Windows & '/" is the delimiter on *Nix (this is a high level difference, but everything adds up). If you want something that isn’t platform specific (as your posts indicated) your stuck with Java (I wonder how far along MONO is) or writing two separate classes and figure out which platform your on at compile time.


                        I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                        G Offline
                        G Offline
                        George_George
                        wrote on last edited by
                        #11

                        Your reply makes senses, Douglas! regards, George

                        S 1 Reply Last reply
                        0
                        • G George_George

                          Your reply makes senses, Douglas! regards, George

                          S Offline
                          S Offline
                          S Douglas
                          wrote on last edited by
                          #12

                          George_George wrote:

                          Your reply makes sense

                          Glad I was able to help. :java: Why vote a 4? Not that it matters at all.


                          I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                          G 1 Reply Last reply
                          0
                          • S S Douglas

                            George_George wrote:

                            Your reply makes sense

                            Glad I was able to help. :java: Why vote a 4? Not that it matters at all.


                            I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                            G Offline
                            G Offline
                            George_George
                            wrote on last edited by
                            #13

                            Hi Douglas, If you could provide sample code, I will rate it to 5. :-) regards, George

                            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