private static void ScanRecursive(int current, int max, List<string> libraryLocations, DirectoryInfo folder)
{
// Make sure we are not too deep
if (max >= current)
{
// Get all the sub folders and iterate over them
DirectoryInfo[] folders;
try
{
folders = folder.GetDirectories();
}
// Make sure we have access to read the folder
catch (UnauthorizedAccessException)
{
return;
}
// Avoid any other errors
catch (IOException)
{
return;
}
foreach (DirectoryInfo f in folders)
{
// Check for special windows directories
if (f.Name.StartsWith("$"))
{
continue;
}
// Check if the directory is a hidden directory
// because we shouldn't search those
if ((f.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
continue;
}
// Another data directory which we should skip
if (f.Name.Equals("Common Files"))
{
continue;
}
// Check if we can a match on the folder
if (!CheckFolder(f, libraryLocations))
{
// We didn't, so we should scan the subfolders
ScanRecursive(current + 1, max, libraryLocations, f);
}
}
}
}