3

I am writing a Cross platform application using C++/STL/Boost and I realized they do not provide a way to check if a folder or file is hidden or is a system file in Windows.

What's the simplest way to do this in C/C++ for Windows ?

Ideally I have a std::string with the path (either to a file or folder), and would return if it's hidden or is a system file. best if it works across all windows versions. I am using MinGW g++ to compile this as well.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
The Unknown
  • 19,224
  • 29
  • 77
  • 93

1 Answers1

6

GetFileAttributes will work for this.

It takes a path to either a file or a directory as a parameter and returns set of flags including FILE_ATTRIBUTE_HIDDEN and FILE_ATTRIBUTE_SYSTEM.

DWORD attributes = GetFileAttributes(path);
if (attributes & FILE_ATTRIBUTE_HIDDEN) ...

if (attributes & FILE_ATTRIBUTE_SYSTEM) ...
Michael
  • 54,279
  • 5
  • 125
  • 144