检查Windows C/C ++中是否隐藏了文件夹/文件/系统 [英] Checking if a Folder/File is Hidden/System in Windows C/C++
问题描述
我正在使用C ++/STL/Boost编写跨平台应用程序,但我意识到他们没有提供检查文件夹或文件是否被隐藏或在Windows中是否为系统文件的方法.
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.
在Windows的C/C ++中最简单的方法是什么?
What's the simplest way to do this in C/C++ for Windows ?
理想情况下,我有一个带有路径(到文件或文件夹)的std :: string,如果它是隐藏的或是系统文件,它将返回.如果适用于所有Windows版本,则效果最佳.我也在用MinGW g ++进行编译.
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.
推荐答案
它将文件或目录的路径作为参数,并返回包括FILE_ATTRIBUTE_HIDDEN和FILE_ATTRIBUTE_SYSTEM在内的标志集.
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) ...
这篇关于检查Windows C/C ++中是否隐藏了文件夹/文件/系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!