Search code examples
c++cwinapi

How can I tell if a given path is a directory or a file? (C/C++)


I'm using C and sometimes I have to handle paths like

  • C:\Whatever
  • C:\Whatever\
  • C:\Whatever\Somefile

Is there a way to check if a given path is a directory or a given path is a file?


Solution

  • Call GetFileAttributes, and check for the FILE_ATTRIBUTE_DIRECTORY attribute.