private static void BuildFileSystem(Folder rootFolder, string currentPath)
{
string currentFullPath = string.Format("{0}\\{1}", currentPath, rootFolder.Name);
DirectoryInfo currentDirectory = new DirectoryInfo(currentFullPath);
DirectoryInfo[] subdirectories = null;
try
{
subdirectories = currentDirectory.GetDirectories();
foreach (DirectoryInfo subdirectory in subdirectories)
{
Folder newChildFolder = new Folder(subdirectory.Name);
rootFolder.AddChildFolder(newChildFolder);
BuildFileSystem(newChildFolder, currentFullPath);
}
}
catch (UnauthorizedAccessException)
{
// Skip directories to which permission to access is not granted
return;
}
FileInfo[] files = null;
try
{
files = currentDirectory.GetFiles();
foreach (FileInfo file in files)
{
rootFolder.AddFile(new File(file.Name, file.Length));
}
}
catch (UnauthorizedAccessException)
{
// Skip files to which permission to access is not granted
return;
}
}