コード例 #1
0
 public Folder GetFolder(string name)
 {
     if (name == "null")
     {
         return GetRoot();
     }
     Folder folder = new Folder();
     DirectoryInfo currentDirectory = new DirectoryInfo(name + "\\");
     try
     {
         folder.InternalFolders.AddRange(currentDirectory.GetDirectories().Select(dir => dir.Name));
         folder = FillFolderInfo(folder, currentDirectory);
         folder.Files.AddRange(currentDirectory.GetFiles().Select(file => file.Name));
         folder.Path = currentDirectory.FullName;
     }
     catch (UnauthorizedAccessException e)
     {
         folder.Path = "UnauthorizedAccessException";
     }
     if (currentDirectory.Parent != null)
     {
         folder.ParentFolderPath = currentDirectory.Parent.FullName;
     }
     return folder;
 }
コード例 #2
0
 private Folder FillFolderInfo(Folder folder, DirectoryInfo directory)
 {
     List<long> sizes = new List<long>();
     sizes.AddRange(directory.GetFiles().Select(file => file.Length));
     foreach (DirectoryInfo subDir in directory.GetDirectories())
     {
         try
         {
             sizes.AddRange(subDir.GetFiles().Select(file => file.Length));
         }
         catch (UnauthorizedAccessException)
         {
             continue;
         }
     }
     foreach (long size in sizes)
     {
         if (size <= 10 * Mb)
         {
             folder.FilesInfo.Less10Mb++;
         }
         else if (size > 10 * Mb && size <= 50 * Mb)
         {
             folder.FilesInfo.From10MbTo50Mb++;
         }
         else if (size >= 100 * Mb)
         {
             folder.FilesInfo.More100Mb++;
         }
     }
     return folder;
 }
コード例 #3
0
 public Folder GetRoot()
 {
     Folder folder = new Folder();
     folder.Path = string.Empty;
     folder.InternalFolders.AddRange(DriveInfo.GetDrives().Where(drive => drive.DriveType == DriveType.Fixed).Select(dir => dir.Name));
     return folder;
 }