Fix GetCorrectCasedPath() to first check if any system file entries is returned before calling First() (#10930)

This commit is contained in:
Steve Lee
2019-10-31 11:42:23 -07:00
committed by Andrew
parent 96eb361af8
commit 229762737d
@@ -155,7 +155,17 @@ namespace Microsoft.PowerShell.Commands
}
else
{
exactPath = Directory.GetFileSystemEntries(exactPath, item).First();
// Use GetFileSystemEntries to get the correct casing of this element
var entries = Directory.GetFileSystemEntries(exactPath, item);
if (entries.Length > 0)
{
exactPath = entries.First();
}
else
{
// If previous call didn't return anything, something failed so we just return the path we were given
return path;
}
}
}