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 with a certain extension

finding files with a certain extension

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
14 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

    I don't understand, are u looking for all files that have a .tga extension?

    S Offline
    S Offline
    shortwave
    wrote on last edited by
    #4

    yes I do

    S 1 Reply Last reply
    0
    • S shortwave

      yes I do

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

      Thanks for your help - but that's not what I need... I need to look for a files that have the same file name each time, but have different extensions. For Example, in my directory there are the files: file.001 file.002 file.x file.y so, I don't need to find the files file.x or file.y. I only need to find the files that have an extension that consists of numbers. The problem is that when I search for files in the format: "file.*", it finds the files named file.x and file.y which I don't need.

      S D 2 Replies Last reply
      0
      • S SWDevil

        Thanks for your help - but that's not what I need... I need to look for a files that have the same file name each time, but have different extensions. For Example, in my directory there are the files: file.001 file.002 file.x file.y so, I don't need to find the files file.x or file.y. I only need to find the files that have an extension that consists of numbers. The problem is that when I search for files in the format: "file.*", it finds the files named file.x and file.y which I don't need.

        S Offline
        S Offline
        shortwave
        wrote on last edited by
        #6

        ok for(.............etc.) sprintf(fileFound, "%s\\file.00%.1d ",ARRAYOFCONST((folderPath,i)) ); now you can search for ectintions from 001 to 009 -- modified at 9:20 Sunday 16th April, 2006

        S 1 Reply Last reply
        0
        • S shortwave

          ok for(.............etc.) sprintf(fileFound, "%s\\file.00%.1d ",ARRAYOFCONST((folderPath,i)) ); now you can search for ectintions from 001 to 009 -- modified at 9:20 Sunday 16th April, 2006

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

          yes - but I don't know what the maximum number the extension could have. There could be a file named file.9999 for instance.. so I can't search until infinity. That's my problem. Maybe there is a way to check if the extension contains only numbers or something like that. Do you know?

          S D 2 Replies Last reply
          0
          • S SWDevil

            yes - but I don't know what the maximum number the extension could have. There could be a file named file.9999 for instance.. so I can't search until infinity. That's my problem. Maybe there is a way to check if the extension contains only numbers or something like that. Do you know?

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

            I dont remember the function name but try this sSearchPath.Format("file.*"); BOOL bWorking = f.FindFile(sSearchPath); int j = 0, i++; while (bWorking) { CString strFileEx = ExtractFileExt(f.GetFileName()); while(strFileEx [j] != '\0' ) { if(!((int)strFileEx [j] >= (int)'0' && (int)strFileEx [j]<='9')) i++; } if(i>0) //do what you want to do bWorking = f.FindNextFile(); } -- modified at 9:57 Sunday 16th April, 2006

            S 1 Reply Last reply
            0
            • S shortwave

              I dont remember the function name but try this sSearchPath.Format("file.*"); BOOL bWorking = f.FindFile(sSearchPath); int j = 0, i++; while (bWorking) { CString strFileEx = ExtractFileExt(f.GetFileName()); while(strFileEx [j] != '\0' ) { if(!((int)strFileEx [j] >= (int)'0' && (int)strFileEx [j]<='9')) i++; } if(i>0) //do what you want to do bWorking = f.FindNextFile(); } -- modified at 9:57 Sunday 16th April, 2006

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

              Thanks! But what is the function "ExtractFileExt"? my code doesn't recognise it. do I need an include for it or something?

              D 1 Reply Last reply
              0
              • S SWDevil

                Hi, I need to find all files in a certain directory that are in the format of: file.001, file.002, etc (the numbers in the file extensions can go up to infinity...). I am using the functions FindFile and FindNextFile to do this (my code is below). The problem is that in the same directory there might also be files named file.x or file.y (for example) which I don't need to find. I only need the files with the number extensions. Is there a way to do this? this is my code: sSearchPath.Format("file.*"); BOOL bWorking = f.FindFile(sSearchPath); while (bWorking) { bWorking = f.FindNextFile(); CString strFileName = f.GetFileName(); } Thanks

                S Offline
                S Offline
                Saurabh Garg
                wrote on last edited by
                #10

                what you can do is determine the extension of the file using GetFileName and GetFileTitle. Then for each charcter in extension check if its a digit using isDigit function. If all the characters in extension are digit then keep file else move to next file. -Saurabh

                1 Reply Last reply
                0
                • S SWDevil

                  Hi, I need to find all files in a certain directory that are in the format of: file.001, file.002, etc (the numbers in the file extensions can go up to infinity...). I am using the functions FindFile and FindNextFile to do this (my code is below). The problem is that in the same directory there might also be files named file.x or file.y (for example) which I don't need to find. I only need the files with the number extensions. Is there a way to do this? this is my code: sSearchPath.Format("file.*"); BOOL bWorking = f.FindFile(sSearchPath); while (bWorking) { bWorking = f.FindNextFile(); CString strFileName = f.GetFileName(); } Thanks

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #11

                  You can use PathFindExtension() to get a pointer to the extension part of the filename, and do string comparisons from there.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                  1 Reply Last reply
                  0
                  • S SWDevil

                    Thanks for your help - but that's not what I need... I need to look for a files that have the same file name each time, but have different extensions. For Example, in my directory there are the files: file.001 file.002 file.x file.y so, I don't need to find the files file.x or file.y. I only need to find the files that have an extension that consists of numbers. The problem is that when I search for files in the format: "file.*", it finds the files named file.x and file.y which I don't need.

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

                    For each file found, including file.x and file.y, simply check the extension to see if it is all digits or not.


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

                    "There is no death, only a change of worlds." - Native American Proverb

                    1 Reply Last reply
                    0
                    • S SWDevil

                      yes - but I don't know what the maximum number the extension could have. There could be a file named file.9999 for instance.. so I can't search until infinity. That's my problem. Maybe there is a way to check if the extension contains only numbers or something like that. Do you know?

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

                      SWDevil wrote:

                      Maybe there is a way to check if the extension contains only numbers or something like that. Do you know?

                      Yes, it's called isdigit().


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

                      "There is no death, only a change of worlds." - Native American Proverb

                      1 Reply Last reply
                      0
                      • S SWDevil

                        Thanks! But what is the function "ExtractFileExt"? my code doesn't recognise it. do I need an include for it or something?

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

                        Why not just use PathFindExtension()?


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

                        "There is no death, only a change of worlds." - 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