public void loadTreeData()
 {
     Drives = new ObservableCollection <FileFolderInfo>();
     foreach (DriveInfo info in DriveInfo.GetDrives())
     {
         if (!AvoidedFilePaths.Split(',').Contains(info.RootDirectory.FullName))
         {
             if (info.IsReady)
             {
                 FileFolderInfo harddriveinfo = new FileFolderInfo();
                 harddriveinfo.FileFolders = new ObservableCollection <FileFolderInfo>();
                 GetDirectoryData(info.RootDirectory, ref harddriveinfo);
                 GetFileInfo(info.RootDirectory, ref harddriveinfo);
                 harddriveinfo.IsDrive = true;
                 harddriveinfo.Name    = info.Name;
                 harddriveinfo.Path    = info.RootDirectory.FullName;
                 Drives.Add(harddriveinfo);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void loadTreeData()
        {
            Drives = new ObservableCollection <FileFolderInfo>();

            //add desktop
            FileFolderInfo desktop = new FileFolderInfo();

            desktop.FileFolders = new ObservableCollection <FileFolderInfo>();
            DirectoryInfo tmp = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));

            GetDirectoryData(tmp, ref desktop);
            GetFileInfo(tmp, ref desktop);
            desktop.IsDrive = true;
            desktop.Name    = "Desktop";
            desktop.Path    = tmp.FullName;
            Drives.Add(desktop);

            //add other drivers
            foreach (DriveInfo info in DriveInfo.GetDrives())
            {
                if (!AvoidedFilePaths.Split(',').Contains(info.RootDirectory.FullName))
                {
                    if (info.IsReady)
                    {
                        FileFolderInfo harddriveinfo = new FileFolderInfo();
                        harddriveinfo.FileFolders = new ObservableCollection <FileFolderInfo>();
                        GetDirectoryData(info.RootDirectory, ref harddriveinfo);
                        GetFileInfo(info.RootDirectory, ref harddriveinfo);
                        harddriveinfo.IsDrive = true;
                        harddriveinfo.Name    = info.Name;
                        harddriveinfo.Path    = info.RootDirectory.FullName;
                        Drives.Add(harddriveinfo);
                    }
                }
            }
        }
 public void GetFileInfo(DirectoryInfo DirectoryInfo, ref FileFolderInfo items)
 {
     if (!SelectedFilter.Contains("*.*"))
     {
         foreach (System.IO.FileInfo directoryinfo in DirectoryInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly).Where(s => SelectedFilter.Split('|')[1].Contains(s.Extension.ToLower())).Where(s => !AvoidedFilePaths.Contains(s.FullName)))
         {
             if ((directoryinfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden && directoryinfo.Extension != "")
             {
                 items.FileFolders.Add(new FileFolderInfo
                 {
                     Name         = directoryinfo.Name,
                     Path         = directoryinfo.FullName,
                     DateModified = directoryinfo.LastWriteTime,
                     IsFile       = true
                 });
             }
         }
     }
     else
     {
         foreach (System.IO.FileInfo directoryinfo in DirectoryInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly).Where(s => !AvoidedFilePaths.Contains(s.FullName)))
         {
             if ((directoryinfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden && directoryinfo.Extension != "")
             {
                 items.FileFolders.Add(new FileFolderInfo
                 {
                     Name         = directoryinfo.Name,
                     Path         = directoryinfo.FullName,
                     DateModified = directoryinfo.LastWriteTime,
                     IsFile       = true
                 });
             }
         }
     }
 }
 public void GetDirectoryData(DirectoryInfo DirectoryInfo, ref FileFolderInfo folder)
 {
     foreach (DirectoryInfo directoryinfo in DirectoryInfo.GetDirectories("*.*", SearchOption.TopDirectoryOnly).Where(s => !AvoidedFilePaths.Contains(s.FullName)))
     {
         if ((directoryinfo.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
         {
             folder.FileFolders.Add(new FileFolderInfo
             {
                 Name         = directoryinfo.Name,
                 Path         = directoryinfo.FullName,
                 IsDirectory  = true,
                 DateModified = directoryinfo.LastWriteTime
                                //Files= GetFileInfo(directoryinfo),
                                //Folders=GetDirectoryData(directoryinfo)
             });
         }
     }
 }