Checking if a Folder/File is Hidden/System in Windows C/C++

混江龙づ霸主 提交于 2020-01-03 19:31:34

问题


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.


回答1:


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) ...


来源:https://stackoverflow.com/questions/1343635/checking-if-a-folder-file-is-hidden-system-in-windows-c-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!