ADDED: IsFileHidden()

This commit is contained in:
Ray
2026-09-04 18:13:28 +02:00
parent 3f3b4ccd4f
commit 3449d81f67

View File

@@ -165,6 +165,7 @@
#if defined(__cplusplus)
extern "C" {
#endif
__declspec(dllimport) unsigned long __stdcall GetFileAttributesA(const char *lpFileName);
__declspec(dllimport) unsigned long __stdcall GetModuleFileNameA(struct HINSTANCE__ *hModule, char *lpFilename, unsigned long nSize);
__declspec(dllimport) unsigned long __stdcall GetModuleFileNameW(struct HINSTANCE__ *hModule, wchar_t *lpFilename, unsigned long nSize);
__declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
@@ -2412,6 +2413,24 @@ bool IsFileExtension(const char *fileName, const char *ext)
return result;
}
// Check if a provided file path (or directory) is hidden by OS
bool IsFileHidden(const char *path)
{
bool result = false;
#if defined(_WIN32)
unsigned long attribs = GetFileAttributesA(path);
// Check !INVALID_FILE_ATTRIBUTES and FILE_ATTRIBUTE_HIDDEN
if ((attribs != -1) && ((attrs & 0x2UL) != 0)) result = true;
#else
const char *base = strrchr(path, '/');
base = (base? base + 1 : path);
if ((base[0] == '.') && (strcmp(base, ".") != 0) && (strcmp(base, "..") != 0)) result = true;
#endif
return result;
}
// Check if directory path exists
bool DirectoryExists(const char *dirPath)
{