diff --git a/src/rcore.c b/src/rcore.c index b1b360dbe..cc777e4b9 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -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) {