Ok, I've got everything working. It seems GetDirectories is actually fast enough when using a search pattern. Thanks for reading through the code, and here's what I'm using now. public List Generate(string generationString) { List results = new List(); string[] pathParts = generationString.Split(Path.DirectorySeparatorChar); DirectoryInfo currentDirectory = null; for (int index = 0; index < pathParts.Length;index++ ) { string pathPart = pathParts[index]; if (index == 0) { //The first part will be the drive. DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo drive in drives) { if (drive.Name.StartsWith(pathPart, StringComparison.InvariantCultureIgnoreCase)) { currentDirectory = drive.RootDirectory; } } if (currentDirectory == null) { break; } } else if ((index == pathParts.Length - 1) ) { //The last part could be anything, so we do a wildcard search. try { results.AddRange(Directory.GetDirectories(currentDirectory.FullName, pathPart + "*")); results.AddRange(Directory.GetFiles(currentDirectory.FullName, pathPart + "*")); } catch { } } else { //Just add the first result to the path. DirectoryInfo[] searchResults = currentDirectory.GetDirectories(pathPart); if (searchResults.Length == 0) { break; } else { currentDirectory = searchResults[0]; } } } return results; }
www.wickedorange.com www.andrewvos.com