diff --git a/Source/FileManager/FileUtility.cs b/Source/FileManager/FileUtility.cs index 4103cb47..c5476258 100644 --- a/Source/FileManager/FileUtility.cs +++ b/Source/FileManager/FileUtility.cs @@ -212,25 +212,23 @@ namespace FileManager { var foundFiles = Enumerable.Empty(); - if (searchOption == SearchOption.AllDirectories) + try { - try + if (searchOption == SearchOption.AllDirectories) { - IEnumerable subDirs = Directory.EnumerateDirectories(path).Select(p => (LongPath)p); + IEnumerable subDirs = Directory.EnumerateDirectories(path).Select(p => (LongPath)p); // Add files in subdirectories recursively to the list foreach (string dir in subDirs) foundFiles = foundFiles.Concat(SaferEnumerateFiles(dir, searchPattern, searchOption)); } - catch (UnauthorizedAccessException) { } - catch (PathTooLongException) { } - } - try - { // Add files from the current directory foundFiles = foundFiles.Concat(Directory.EnumerateFiles(path, searchPattern).Select(f => (LongPath)f)); } catch (UnauthorizedAccessException) { } + catch (PathTooLongException) { } + // Symbolic links will result in DirectoryNotFoundException. Ohter logical directories might also. Just skip them. Don't want to risk (or have to handle) infinite recursion + catch (DirectoryNotFoundException) { } return foundFiles; }