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. Finding files using FindFile/FindNextFile

Finding files using FindFile/FindNextFile

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
11 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.
  • S SWDevil

    Hi, I use the FindFile(sCurrImgPath) and FindNextFile functions to search for files of the format file*.x (where the * is a number) in a directory. The problem is that these functions return the file names in the following order (for example): file1.x file10.x file11.x file2.x file20.x file3.x etc... and I need the files in the order: file1.x file2.x file3.x file10.x file20.x etc... How can I do this? -- modified at 2:21 Thursday 9th March, 2006

    N Offline
    N Offline
    Nibu babu thomas
    wrote on last edited by
    #2

    That is how it will be because when comparing strings file10 is less than file2 so it comes up in the order. If you have file numbering like file01, file02, you can avoid these problems. But you cannot expect this.


    Nibu thomas Software Developer

    S 1 Reply Last reply
    0
    • N Nibu babu thomas

      That is how it will be because when comparing strings file10 is less than file2 so it comes up in the order. If you have file numbering like file01, file02, you can avoid these problems. But you cannot expect this.


      Nibu thomas Software Developer

      S Offline
      S Offline
      SWDevil
      wrote on last edited by
      #3

      Nibu thomas wrote:

      If you have file numbering like file01, file02, you can avoid these problems. But you cannot expect this.

      I don't have the files numbered this way, and I can't change their names... is there a way to sort the names of the files after I get all of the file names?

      H 1 Reply Last reply
      0
      • S SWDevil

        Nibu thomas wrote:

        If you have file numbering like file01, file02, you can avoid these problems. But you cannot expect this.

        I don't have the files numbered this way, and I can't change their names... is there a way to sort the names of the files after I get all of the file names?

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

        CComboBox m_Combo; m_Combo.Create(WS_CHILD,CRect(0,0,0,0),this,1); m_Combo.Dir(DDL_ARCHIVE|DDL_DIRECTORY, _T("*.*")); and you can inactive sort in the propery page -- modified at 3:20 Thursday 9th March, 2006

        S 1 Reply Last reply
        0
        • H Hamid Taebi

          CComboBox m_Combo; m_Combo.Create(WS_CHILD,CRect(0,0,0,0),this,1); m_Combo.Dir(DDL_ARCHIVE|DDL_DIRECTORY, _T("*.*")); and you can inactive sort in the propery page -- modified at 3:20 Thursday 9th March, 2006

          S Offline
          S Offline
          SWDevil
          wrote on last edited by
          #5

          I don't understand what you meant... did you mean to add to my project a combo box that will list the files, and then use it's sort property to sort the names?

          H 1 Reply Last reply
          0
          • S SWDevil

            I don't understand what you meant... did you mean to add to my project a combo box that will list the files, and then use it's sort property to sort the names?

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

            CComboBox m_Combo; CString m_str; m_Combo.Create(WS_CHILD,CRect(0,0,0,0),this,1); m_Combo.Dir(DDL_ARCHIVE, _T("*.*")); for (int i=0;i

            T 1 Reply Last reply
            0
            • S SWDevil

              Hi, I use the FindFile(sCurrImgPath) and FindNextFile functions to search for files of the format file*.x (where the * is a number) in a directory. The problem is that these functions return the file names in the following order (for example): file1.x file10.x file11.x file2.x file20.x file3.x etc... and I need the files in the order: file1.x file2.x file3.x file10.x file20.x etc... How can I do this? -- modified at 2:21 Thursday 9th March, 2006

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #7

              2 possibilities : if you can rename the files, change file1.x, file2.x, to file01.x, file02.x, etc... if you're not allowed to change the file names, then firstly search for "file?.x" files, then when you've got them, search for "file??.x"...

              S 1 Reply Last reply
              0
              • H Hamid Taebi

                CComboBox m_Combo; CString m_str; m_Combo.Create(WS_CHILD,CRect(0,0,0,0),this,1); m_Combo.Dir(DDL_ARCHIVE, _T("*.*")); for (int i=0;i

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #8

                a combo box is a displaying matter. what the guy does is a background treatment, typically for a controler... moreover, you are using a MFC class when no way the guy said that it was using MFC... very bad method so.

                1 Reply Last reply
                0
                • T toxcct

                  2 possibilities : if you can rename the files, change file1.x, file2.x, to file01.x, file02.x, etc... if you're not allowed to change the file names, then firstly search for "file?.x" files, then when you've got them, search for "file??.x"...

                  S Offline
                  S Offline
                  SWDevil
                  wrote on last edited by
                  #9

                  I can't rename the files... so I'll have to go for the second possibility.. :) but FindFile doesn't accept question marks, it accepts * to signify a wild card. so when I write file*.x and file **.x, it gives the same result... Is there a way to get all of the files that have one number after the file, then find all the files that have two numbers after the file, etc.?

                  W T 2 Replies Last reply
                  0
                  • S SWDevil

                    I can't rename the files... so I'll have to go for the second possibility.. :) but FindFile doesn't accept question marks, it accepts * to signify a wild card. so when I write file*.x and file **.x, it gives the same result... Is there a way to get all of the files that have one number after the file, then find all the files that have two numbers after the file, etc.?

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

                    Why don't you get the files in a linked list and then sort the list? In that case you can sort the list in any type of order you need. Basically, the suggested solution with the combobox does the same, but you can keep it all in your own hands just as easily. Suggestion for a linked list: typedef struct _st_list ST_LIST; struct_st_list { CString m_strFilename; ST_LIST * m_Next; }; ST_LIST * MyList = (ST_LIST *)NULL; ST_LIST * NewList (void) { ST_LIST *r, *l; r = new ST_LIST; r->m_Next = (ST_LIST *)NULL; if ((l = MyList) == (ST_LIST *)NULL) MyList = r; else { while (l->m_Next != (ST_LIST *)NULL) l = l->m_Next; l->m_Next = r; } return r; } William

                    1 Reply Last reply
                    0
                    • S SWDevil

                      I can't rename the files... so I'll have to go for the second possibility.. :) but FindFile doesn't accept question marks, it accepts * to signify a wild card. so when I write file*.x and file **.x, it gives the same result... Is there a way to get all of the files that have one number after the file, then find all the files that have two numbers after the file, etc.?

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #11

                      see SADirRead[^] article...

                      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