diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index fd101e0e124dbd07778a4752ea47c880f3e494ca..1384f3f5b8a56e1a12b355618f4341f98497ef9b 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -577,9 +577,9 @@ bool fexist(const char *filespec)
 }
 
 /****************************************************************************/
-/* Fixes upper/lowercase filename for Unix file systems						*/
+/* Fixes upper/lowercase filename or dirname for Unix file systems			*/
 /****************************************************************************/
-bool fexistcase(char *path)
+static bool getfilecase(char *path, bool dir)
 {
 #if defined(_WIN32)
 
@@ -595,7 +595,7 @@ bool fexistcase(char *path)
 
  	_findclose(handle);
 
- 	if(f.attrib&_A_SUBDIR)
+	if(INT_TO_BOOL(f.attrib&_A_SUBDIR) != dir)
 		return(false);
 
 	fname=getfname(path);	/* Find filename in path */
@@ -636,7 +636,7 @@ bool fexistcase(char *path)
 	}
 #endif
 
-	if(glob(globme,GLOB_MARK,NULL,&glb) != 0)
+	if(glob(globme, dir ? GLOB_ONLYDIR : GLOB_MARK, NULL, &glb) != 0)
 		return(false);
 
 	if(glb.gl_pathc>0)  {
@@ -657,6 +657,16 @@ bool fexistcase(char *path)
 #endif
 }
 
+bool fexistcase(char *path)
+{
+	return getfilecase(path, false);
+}
+
+bool getdircase(char* path)
+{
+	return getfilecase(path, true);
+}
+
 /****************************************************************************/
 /* Returns true if the filename specified is a directory					*/
 /****************************************************************************/
diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h
index c84c9b9e750d705cce8b770d7ef05e03866b98a0..d9f4f7a33d524e05d18dd6c304d1e8d2482d1db1 100644
--- a/src/xpdev/dirwrap.h
+++ b/src/xpdev/dirwrap.h
@@ -219,6 +219,7 @@ DLLEXPORT char*		getfext(const char* path);
 DLLEXPORT int		getfattr(const char* filename);
 DLLEXPORT int		getfmode(const char* filename);
 DLLEXPORT uint		getfilecount(const char *path);
+DLLEXPORT bool		getdircase(char* path);
 DLLEXPORT char*		getdirname(const char* path);
 DLLEXPORT size_t	getdirsize(const char* path, bool include_subdirs, bool subdir_only);
 DLLEXPORT uint64_t	getdisksize(const char* path, uint64_t unit);