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. How do you know if it's a file or directory

How do you know if it's a file or directory

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 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.
  • N Offline
    N Offline
    no_reg_name
    wrote on last edited by
    #1

    Given a path e.g. c:\somedir1\somedir2\file.txt how can you find out if file.txt is a directory or a file? Can't base the judgement on the extension, since there could be a directory named file.txt. :( On a side note I have an application that is using FindFirstFile and FindNextFile to enumerate all files and subdirectories in a given path. Now I want to check if this given path is a pointing to a file, so I could ShellExecute the file, instead of calling the above functions. :)

    A N 2 Replies Last reply
    0
    • N no_reg_name

      Given a path e.g. c:\somedir1\somedir2\file.txt how can you find out if file.txt is a directory or a file? Can't base the judgement on the extension, since there could be a directory named file.txt. :( On a side note I have an application that is using FindFirstFile and FindNextFile to enumerate all files and subdirectories in a given path. Now I want to check if this given path is a pointing to a file, so I could ShellExecute the file, instead of calling the above functions. :)

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      Test FindFirstFile() etc. WIN32_FIND_DATA.dwFileAttributes for FILE_ATTRIBUTE_DIRECTORY. Should do the trick. Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

      1 Reply Last reply
      0
      • N no_reg_name

        Given a path e.g. c:\somedir1\somedir2\file.txt how can you find out if file.txt is a directory or a file? Can't base the judgement on the extension, since there could be a directory named file.txt. :( On a side note I have an application that is using FindFirstFile and FindNextFile to enumerate all files and subdirectories in a given path. Now I want to check if this given path is a pointing to a file, so I could ShellExecute the file, instead of calling the above functions. :)

        A Offline
        A Offline
        Antony M Kancidrowski
        wrote on last edited by
        #3

        To check for directory you need to check the dwFileAttributes of the WIN32_FIND_DATA structure that you pass to FindFirstFile or FindNextFile

        WIN32_FIND_DATA data;
        ...
        // Is the found item a directory
        if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
        ...
        }

        Ant. I'm hard, yet soft.
        I'm coloured, yet clear.
        I'm fuity and sweet.
        I'm jelly, what am I? Muse on it further, I shall return!
        - David Williams (Little Britain)

        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