diff --git a/mongoose.c b/mongoose.c
index a5a16885ac8c8cdd1991acff2638afe3c878f390..9d15bef798c70b106466dc81f257adae8af95b89 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -1277,10 +1277,9 @@ static void to_wchar(const char *path, wchar_t *wbuf, size_t wbuf_len) {
   strncpy(buf, path, sizeof(buf));
   buf[sizeof(buf) - 1] = '\0';
 
-  // Trim trailing slashes
+  // Trim trailing slashes. Leave backslash for paths like X:\
   p = buf + strlen(buf) - 1;
-  while (p > buf && p[0] == '\\' || p[0] == '/') *p-- = '\0';
-  //change_slashes_to_backslashes(buf);
+  while (p > buf && p[-1] != ':' && (p[0] == '\\' || p[0] == '/')) *p-- = '\0';
 
   // Convert to Unicode and back. If doubly-converted string does not
   // match the original, something is fishy, reject.