diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index cc284591d1cb8bd98352be4b13eda5c7fb4d7ab0..bb8985ea76fe0185848e4a77146357fc0bbfa429 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -497,17 +497,33 @@ BOOL DLLCALL fexistcase(char *path)
 #endif
 }
 
+#if !defined(S_ISDIR)
+	#define S_ISDIR(x)	((x)&S_IFDIR)
+#endif
+
 /****************************************************************************/
 /* Returns TRUE if the filename specified is a directory					*/
 /****************************************************************************/
 BOOL DLLCALL isdir(const char *filename)
 {
+	char	path[MAX_PATH+1];
+	char*	p;
 	struct stat st;
 
-	if(stat(filename, &st)!=0)
+	SAFECOPY(path,filename);
+
+	p=lastchar(path);
+	if(p!=path && (*p=='/' || *p==BACKSLASH)) {	/* chop off trailing slash */
+#if !defined(__unix__)
+		if(*(p-1)!=':')		/* Don't change C:\ to C: */
+#endif
+			*p=0;
+	}
+
+	if(stat(path, &st)!=0)
 		return(FALSE);
 
-	return((st.st_mode&S_IFDIR) ? TRUE : FALSE);
+	return(S_ISDIR(st.st_mode) ? TRUE : FALSE);
 }
 
 /****************************************************************************/