public static NTree <PathInfo> GetDirectoryTree(string path, out ulong FileCount, out ulong DirectoryCount)
        {
            var cur_dir = path;
            var bfsQ    = new Queue <NNode <PathInfo> >();
            var root    = new NNode <PathInfo>(new PathInfo {
                Path = path
            });
            var cur_node = root;

            bfsQ.Enqueue(root);
            ulong dirCounter = 1, fileCounter = 0;

            while (bfsQ.Count > 0)
            {
                cur_node = bfsQ.Dequeue();
                var subdirs = FastFileOperations.GetDirectoriesAndFiles(cur_node.Value.Path);
                foreach (var sd in subdirs)
                {
                    var child = new NNode <PathInfo>(sd);
                    bfsQ.Enqueue(child);
                    cur_node.AddChild(child);
                    dirCounter++;
                }
            }
            var dirTree = new NTree <PathInfo>(root);

            FileCount      = fileCounter;
            DirectoryCount = dirCounter;
            return(dirTree);
        }
Esempio n. 2
0
 {    /// <summary>
     ///
     /// </summary>
     /// <param name="ft"></param>
     /// <param name="IsRerun">To be implemented</param>
     public static void Refresh(this NTree <PathInfo> ft, bool IsRerun = false)
     {
         ft.BFS(o => { o.Nodes = 0; if (!o.Value.IsFile)
                       {
                           o.Value.Size = 0;
                       }
                       return(null); });
         ft.DFS(o =>
         {
             if (o.Value.IsFile && o.Value.Size == 0)
             {
                 o.Value.Size = FastFileOperations.GetFileSize(o.Value.Path);
             }
             if (o.Parent != null)
             {
                 o.Parent.Value.Size += o.Value.Size;
                 o.Parent.Nodes      += o.Nodes;
             }
             return(null);
         },
                VisitingOrder.Post);
     }