Disk usage analysis

Modeled on the disk usage analyzer under Ubuntu using WPF made a similar software, reference https://github.com/Caliburn-Micro/Caliburn.Micro/tree/3.2.0/samples/features/Features.WPF use Caliburn. Micro framework completed

Disk Usage Analyzer under Ubuntu

 

Project Address: https://github.com/ALittleDruid/DiskSpaceAnalyse

 

Core code

public void Analyse()                                                                                                                                                                  
{                                                                                                                                                                                      
    if (Parent != null && !string.IsNullOrEmpty(FolderName) && Directory.Exists(FolderName))                                                                                           
    {                                                                                                                                                                                  
        DirectoryInfo di = newThe DirectoryInfo (FolderName);                                                                                                                              
         IF ! ((Di.Attributes & FileAttributes.Directory) = 0 )                                                                                                                           
        {                                                                                                                                                                               
            the try                                                                                                                                                                         
            {                                                                                                                                                                           
                var Files = di.GetFiles ();
                 var dirs = di.GetDirectories (); // access rights catalog no part will be extremely after catching exceptions can be ignored
                FileCount = files.Length;                                                                                                                                              
                FolderCount = dirs.Length;                                                                                                                                             
                foreach (FileInfo fi in files)                                                                                                                                         
                {                                                                                                                                                                      
                    Size += fi.Length;                                                                                                                                                 
                }                                                                                                                                                                      
                foreach (var item in dirs)                                                                                                                                             
                {                                                                                                                                                                       
                    IF ! ((Item.Attributes & FileAttributes.ReparsePoint) = 0 new new)                                                                                                          
                    {                                                                                                                                                                   
                        Continue ; // Ignore symbolic links, or it may result in an infinite recursion                
                    }                                                                                                                                                                  
                     var D = FolderTreeModel (item.FullName, the this );                                                                                                                  
                    Children.Add (D);                                                                                                                                                    
                }                                                                                                                                                                       
                the foreach ( var Item in Children)                                                                                                                                         
                {                                                                                                                                                                       
                    Item.Analyse (); // no need to worry too much lead layers recursive overflow Stack 
                }                                                                                                                                                                       
            }                                                                                                                                                                           
            the catch                                                                                                                                                                      
            {                                                                                                                                                                          
            }                                                                                                                                                                          
            var tmp = newList <FolderTreeModel> (Children); 
            Children.Clear (); 
            Children.AddRange (tmp.OrderByDescending (X => x.size)); // press folder size sorting 
            Parent.Size + =  Size;
        }                                                                                                                                                                               
    }                                                                                                                                                                                  
}                                                                                                                                                                                      

 

Guess you like

Origin www.cnblogs.com/ALittleDruid/p/11442185.html