private async Task <FsItemSize> CalculateDirectorySize(WebDavDirectoryInfo di)
        {
            Stack <WebDavDirectoryInfo> stack = new Stack <WebDavDirectoryInfo>();

            stack.Push(di);

            FsItemSize result = new FsItemSize();

            while (stack.Count > 0)
            {
                var dir = stack.Pop();
                result.DirectoryCount++;

                foreach (var item in dir.DirectoryItems)
                {
                    if (item.IsCollection)
                    {
                        var directoryInfo = await GetDirectoryInfo(item.Uri);

                        stack.Push(directoryInfo);
                    }
                    else
                    {
                        result.Size += item.ContentLength ?? 0;
                        result.FileCount++;
                    }
                }
            }

            return(result);
        }
예제 #2
0
        private Task <FsItemSize> CalculateDirectorySize(DirectoryInfo di)
        {
            Stack <DirectoryInfo> stack = new Stack <DirectoryInfo>();

            stack.Push(di);

            FsItemSize result = new FsItemSize();

            while (stack.Count > 0)
            {
                var dir = stack.Pop();
                result.DirectoryCount++;
                foreach (var file in dir.EnumerateFiles())
                {
                    result.Size += file.Length;
                    result.FileCount++;
                }

                foreach (var item in dir.EnumerateDirectories())
                {
                    //result.DirectoryCount++;
                    stack.Push(item);
                }
            }

            return(Task.FromResult(result));
        }