From 945ba5709f763cb01dcea24e2d3c62021ecaeeea Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 1 May 2024 10:43:56 +0200 Subject: [PATCH] filesystem: add File_DirExists function --- include/libtrx/filesystem.h | 2 ++ src/filesystem.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/libtrx/filesystem.h b/include/libtrx/filesystem.h index 14934b0..dd730db 100644 --- a/include/libtrx/filesystem.h +++ b/include/libtrx/filesystem.h @@ -17,6 +17,8 @@ typedef enum { typedef struct MYFILE MYFILE; +bool File_DirExists(const char *path); + bool File_IsAbsolute(const char *path); bool File_IsRelative(const char *path); diff --git a/src/filesystem.c b/src/filesystem.c index dd306d4..f073542 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -144,6 +144,18 @@ const char *File_GetGameDirectory(void) return m_GameDir; } +bool File_DirExists(const char *path) +{ + char *full_path = File_GetFullPath(path); + DIR *dir = opendir(path); + Memory_FreePointer(&full_path); + if (dir != NULL) { + closedir(dir); + return true; + } + return false; +} + bool File_Exists(const char *path) { char *full_path = File_GetFullPath(path);