From 0c0375f8ae6ff4c9ac14b36611153d02b7dd6e96 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 2 Jul 2026 10:49:31 +0200 Subject: [PATCH] ADDED: `IsPathDirectory()`, for convenience and more readability at user code --- src/raylib.h | 3 ++- src/rcore.c | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 445b0a875..35f3c40a9 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1160,7 +1160,8 @@ RLAPI const char *GetWorkingDirectory(void); // Get curre RLAPI const char *GetApplicationDirectory(void); // Get the directory of the running application (uses static string) RLAPI int MakeDirectory(const char *dirPath); // Create directories (including full path requested), returns 0 on success RLAPI int ChangeDirectory(const char *dirPath); // Change working directory, returns 0 on success -RLAPI bool IsPathFile(const char *path); // Check if given path is a file or a directory +RLAPI bool IsPathFile(const char *path); // Check if given path points to a file +RLAPI bool IsPathDirectory(const char *path); // Check if given path points to a directory RLAPI bool IsFileNameValid(const char *fileName); // Check if fileName is valid for the platform/OS RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths, files and directories, no subdirs scan RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and subdir scan; some filters available: '*.*','FILES*','DIRS*' diff --git a/src/rcore.c b/src/rcore.c index 070b8c0c4..d1163a515 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -2825,10 +2825,24 @@ int ChangeDirectory(const char *dirPath) // Check if given path point to a file bool IsPathFile(const char *path) { - struct stat result = { 0 }; - stat(path, &result); + bool result = false; - return S_ISREG(result.st_mode); + struct stat info = { 0 }; + stat(path, &info); + + if (S_ISREG(info.st_mode)) result = true; + + return result; +} + +// Check if given path point to a directory +bool IsPathDirectory(const char *path) +{ + bool result = false; + + if (!IsPathFile(path)) result = true; + + return result; } // Check if fileName is valid for the platform/OS