private void Search(String dir, int level) { progressSink.ReportProgress(dir); if (progressSink.Cancelled) { return; } if (Path.GetFileName(dir).ToLower() == "bin") { results.Add(dir); return; // No need to descend further } // If this is not a 'bin' directory, search its children if (level < maxDepth) { try { foreach (var subdir in Directory.EnumerateDirectories(dir)) { Search(subdir, level + 1); if (progressSink.Cancelled) { return; } } } catch (SecurityException) { // Ignore } catch (UnauthorizedAccessException) { // Ignore } } }
private void Search(String dir, int level) { progressSink.ReportProgress(dir); if (progressSink.Cancelled) { return; } if (Path.GetFileName(dir).ToLower() == "bin") { progressSink.FoundCandidate(dir); result.Add(dir); return; // No need to descend further } // Skip the Windows directory. It's huge and the chance of bounty is small. if (Path.GetFullPath(dir).ToLower() == Environment.GetEnvironmentVariable("windir").ToLower()) { return; } // If this is not a 'bin' directory, search its children if (level < maxDepth) { try { foreach (var subdir in Directory.EnumerateDirectories(dir)) { Search(subdir, level + 1); if (progressSink.Cancelled) { return; } } } catch (SecurityException) { // Ignore } catch (UnauthorizedAccessException) { // Ignore } } }