diff --git a/SystemTools.cxx b/SystemTools.cxx
index 2bb4450d267d09a8320529d40cb820323b4c231c..f8311fc535ac8672f0393195b8516986bef8428a 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3058,6 +3058,11 @@ kwsys_stl::string SystemTools::GetActualCaseForPath(const char* p)
     {
     return p;
     }
+  // Use original path if conversion back to a long path failed.
+  if(longPath == shortPath)
+    {
+    longPath = p;
+    }
   // make sure drive letter is always upper case
   if(longPath.size() > 1 && longPath[1] == ':')
     {