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. Non Recursive Folder Traversal

Non Recursive Folder Traversal

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structuresperformance
8 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.
  • B Offline
    B Offline
    bikram singh
    wrote on last edited by
    #1

    The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram

    D J J J 4 Replies Last reply
    0
    • B bikram singh

      The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram

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

      Bikram Singh wrote: What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? Sure there is. Just call SetCurrentDirectory() with each directory encountered.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      B 1 Reply Last reply
      0
      • B bikram singh

        The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram

        J Offline
        J Offline
        Jim Crafton
        wrote on last edited by
        #3

        If your program in a Win32 app with a message loop you could use PostMessage to do the whole thing asynchronously, and then in the main function use a event loop to wait till it was all done. Dunno how efficient that is :) ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned

        1 Reply Last reply
        0
        • D David Crow

          Bikram Singh wrote: What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? Sure there is. Just call SetCurrentDirectory() with each directory encountered.


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          B Offline
          B Offline
          bikram singh
          wrote on last edited by
          #4

          Do you have some source code for the entire problem? Bikram

          D 1 Reply Last reply
          0
          • B bikram singh

            Do you have some source code for the entire problem? Bikram

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

            No. I've personally not ever used the function. It's a hold-over from the Unix world and its single-threaded environment. For Windows and multi-threaded applications, if another thread is running, the "current directory" is constantly changing for all of the threads. For anything that requires folder traversal, I always use recursion. Can you explain in more detail your hesitation in using this methodology?


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            1 Reply Last reply
            0
            • B bikram singh

              The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram

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

              Search in this board for an algorithm I posted a week ago or so to recurse a directory. This uses SetCurrentDirectory() and uses minimal stack. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

              D 1 Reply Last reply
              0
              • J Joe Woodbury

                Search in this board for an algorithm I posted a week ago or so to recurse a directory. This uses SetCurrentDirectory() and uses minimal stack. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

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

                I tried this for almost an hour yesterday because I knew I had just recently seen an example. All that I could find was a post from coremn.


                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                1 Reply Last reply
                0
                • B bikram singh

                  The usual technique of traversing a folder and all it's sub-folders is pretty commonplace, but it suffers from the fact that the stack just might run out (sure, we can specify the stack size in vc, but we dont want to hog a lot of memory for the stack!). What is a good way to use a non-recursive loop to traverse folders? Is there no solution apart from using "goto" statements? :eek: Bikram

                  J Offline
                  J Offline
                  Joel Lucsy
                  wrote on last edited by
                  #8

                  It's pretty easy. Something like: CStringList dirs, files; CString dir; CFileFind ff; BOOL ok; dirs.AddTail("c:\\work\\lisp"); while (!dirs.IsEmpty()) { dir = dirs.RemoveHead(); if (ff.FindFile( dir + "\\*.*" )) { do { ok = ff.FindNextFile(); if (ff.IsDots()) continue; if (ff.IsDirectory()) { dirs.AddTail( ff.GetFilePath() ); continue; } files.AddTail( ff.GetFilePath() ); }while (ok); } } -- Joel Lucsy

                  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