diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index 8cf038e59..3b5749f5e 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -241,7 +241,7 @@ private IEnumerable RecursivelyEnumerateFiles(string folderPath) try { - IEnumerable subDirs = Directory.EnumerateDirectories(folderPath); + IEnumerable subDirs = Directory.GetDirectories(folderPath); foreach (string dir in subDirs) { foundFiles = @@ -274,14 +274,26 @@ private IEnumerable RecursivelyEnumerateFiles(string folderPath) { foundFiles = foundFiles.Concat( - Directory.EnumerateFiles( + Directory.GetFiles( folderPath, pattern)); } - catch (UnauthorizedAccessException e) + catch (DirectoryNotFoundException e) { this.logger.WriteException( - $"Could not enumerate files in the path '{folderPath}' due to a file not being accessible", + $"Could not enumerate files in the path '{folderPath}' due to a path being an invalid path", + e); + } + catch (PathTooLongException e) + { + this.logger.WriteException( + $"Could not enumerate files in the path '{folderPath}' due to a path being too long", + e); + } + catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) + { + this.logger.WriteException( + $"Could not enumerate files in the path '{folderPath}' due to a path not being accessible", e); } }