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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Read file types for all files in a specified directory

Read file types for all files in a specified directory

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
6 Posts 3 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.
  • H Offline
    H Offline
    hkl
    wrote on last edited by
    #1

    I posted a question earlier asking how I can read all files in an user specified directory. Thanks for all the answers. However, I'm wondering if it's possible to read or check the file type (eg. .txt, .doc, or a folder) as well?? Thanks for any help.:)

    D A 2 Replies Last reply
    0
    • H hkl

      I posted a question earlier asking how I can read all files in an user specified directory. Thanks for all the answers. However, I'm wondering if it's possible to read or check the file type (eg. .txt, .doc, or a folder) as well?? Thanks for any help.:)

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

      Well, a file's type and its extension are not necessarily indictive of the other. In other words, I can create a .DOC file with Word, and change the extension to .XYZ. Now what do I have? You can determine if a given entity is a folder or not by looking at the attrib member of the _finddata_t structure mentioned earlier. You can also look at the dwFileAttributes member of the WIN32_FIND_DATA structure.


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      H 1 Reply Last reply
      0
      • D David Crow

        Well, a file's type and its extension are not necessarily indictive of the other. In other words, I can create a .DOC file with Word, and change the extension to .XYZ. Now what do I have? You can determine if a given entity is a folder or not by looking at the attrib member of the _finddata_t structure mentioned earlier. You can also look at the dwFileAttributes member of the WIN32_FIND_DATA structure.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        H Offline
        H Offline
        hkl
        wrote on last edited by
        #3

        Yeah, that's true. The extension can be changed. So, I guess I will have to write a function to check that, assuming the file extensions are correct. I am using the attrib member of the _finddata_t structure. It turns out that a folder is 16 whereas a .txt is 32 or 33. Can you please tell me what those numbers represent?! Thanks.

        D 1 Reply Last reply
        0
        • H hkl

          Yeah, that's true. The extension can be changed. So, I guess I will have to write a function to check that, assuming the file extensions are correct. I am using the attrib member of the _finddata_t structure. It turns out that a folder is 16 whereas a .txt is 32 or 33. Can you please tell me what those numbers represent?! Thanks.

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

          hkl wrote: Can you please tell me what those numbers represent?! Take a look at lines 92-97 of dos.h, and lines 140-145 of io.h.


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          H 1 Reply Last reply
          0
          • D David Crow

            hkl wrote: Can you please tell me what those numbers represent?! Take a look at lines 92-97 of dos.h, and lines 140-145 of io.h.


            Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

            H Offline
            H Offline
            hkl
            wrote on last edited by
            #5

            Thanks so much! I will take a look at that! :cool:

            1 Reply Last reply
            0
            • H hkl

              I posted a question earlier asking how I can read all files in an user specified directory. Thanks for all the answers. However, I'm wondering if it's possible to read or check the file type (eg. .txt, .doc, or a folder) as well?? Thanks for any help.:)

              A Offline
              A Offline
              algol
              wrote on last edited by
              #6

              You could get string description of file's type using SHGetFileInfo() API function with SHGFI_TYPENAME flag.

              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