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. FindNextFile( ) not working in 2nd iteration

FindNextFile( ) not working in 2nd iteration

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 4 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.
  • Z Offline
    Z Offline
    zahid_ash
    wrote on last edited by
    #1

    HI, Suppose I have following files FileA.txt, FileB.txt, FileC.txt, FileD.txt, FileE.txt in the Directory C:\\Files\\ I want to create new files like FileA-FileB.txt merging the text of both files. Then FileA-FileC.txt then another FileA-FileD.txt, then FileA-FileE.txt I have created the above all the first file and its combination with other files but the problem is in remaing Means create the combinations of one file with all other. After first one create FileB-FileC, then FileB-FileD , then FileB-FileE . after that skip second one and create the combination of 3rd and forth file. so on When I ends up with first file combiantoin with other then I do BOOL find = finder.FindFile("C:\\Files\\FileA.txt"); BOOL get = finder.FindNextFile(); // to get the second file again , to make its combinations but here get give false; Why not it finds again the next file to the fileA. and return true. Thanks Regards.

    S R 2 Replies Last reply
    0
    • Z zahid_ash

      HI, Suppose I have following files FileA.txt, FileB.txt, FileC.txt, FileD.txt, FileE.txt in the Directory C:\\Files\\ I want to create new files like FileA-FileB.txt merging the text of both files. Then FileA-FileC.txt then another FileA-FileD.txt, then FileA-FileE.txt I have created the above all the first file and its combination with other files but the problem is in remaing Means create the combinations of one file with all other. After first one create FileB-FileC, then FileB-FileD , then FileB-FileE . after that skip second one and create the combination of 3rd and forth file. so on When I ends up with first file combiantoin with other then I do BOOL find = finder.FindFile("C:\\Files\\FileA.txt"); BOOL get = finder.FindNextFile(); // to get the second file again , to make its combinations but here get give false; Why not it finds again the next file to the fileA. and return true. Thanks Regards.

      S Offline
      S Offline
      swaapu
      wrote on last edited by
      #2

      Hello! Ur question is not very clear. "If you change then change for the good."

      1 Reply Last reply
      0
      • Z zahid_ash

        HI, Suppose I have following files FileA.txt, FileB.txt, FileC.txt, FileD.txt, FileE.txt in the Directory C:\\Files\\ I want to create new files like FileA-FileB.txt merging the text of both files. Then FileA-FileC.txt then another FileA-FileD.txt, then FileA-FileE.txt I have created the above all the first file and its combination with other files but the problem is in remaing Means create the combinations of one file with all other. After first one create FileB-FileC, then FileB-FileD , then FileB-FileE . after that skip second one and create the combination of 3rd and forth file. so on When I ends up with first file combiantoin with other then I do BOOL find = finder.FindFile("C:\\Files\\FileA.txt"); BOOL get = finder.FindNextFile(); // to get the second file again , to make its combinations but here get give false; Why not it finds again the next file to the fileA. and return true. Thanks Regards.

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        FindNextFile() finds the next file that matches the pattern given in the call to FindFile(). Since you've only given one file name to FindFile(), FindNextFile() will always return false. To get all the text files, specify "C:\\Files\\*.txt" in the call to FindFile()

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        Z 1 Reply Last reply
        0
        • R Ryan Binns

          FindNextFile() finds the next file that matches the pattern given in the call to FindFile(). Since you've only given one file name to FindFile(), FindNextFile() will always return false. To get all the text files, specify "C:\\Files\\*.txt" in the call to FindFile()

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          Z Offline
          Z Offline
          zahid_ash
          wrote on last edited by
          #4

          In the 2nd iteration of upper loop , will not it again retuen the first file with *.text that will again be FileA, I want to get the 2nd file in 2nd iteration that is FileB , and 3rd file in 3rd iteration. In the inner loop its iterating to all file once then again come to outer loop Regards.

          W 1 Reply Last reply
          0
          • Z zahid_ash

            In the 2nd iteration of upper loop , will not it again retuen the first file with *.text that will again be FileA, I want to get the 2nd file in 2nd iteration that is FileB , and 3rd file in 3rd iteration. In the inner loop its iterating to all file once then again come to outer loop Regards.

            W Offline
            W Offline
            Wim Engberts
            wrote on last edited by
            #5

            No, if you call CFileFind::FindFile ("*.txt"), then it will give you the next file at each itteration of CFileFind::FindNextFile (). There are two remarks to be made: 1. You MUST call FindNextFile at least once before you can use the outcome of CFileFind. You cannot use the filename immediately after the call to FindFile. So what you do is: bLoop = Finder.FindFile ("*.txt", 0) while (bLoop) { bLoop = Finder.FindNextFile (); now you can use Finder.GetPath () or whatever } 2. There is no telling on the order in which you will receive the filenames. They will come in the order in which they happen to have been registered in the directory. If you need to handle the files in any particular order (e.g. alphabetically or based on age or whatever), you will need to first get all the filenames in a linked list or something like that, then sort them to the desired order and then use the files Regards

            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