private void Format() { _formattedDirectories = new Dictionary <string, Size>(); foreach (var dir in _directories) { string formattedPath = dir.Path.FullPath; var ancestors = _directories.Where(d => dir.Path.IsDescendantOf(d.Path)); if (ancestors.Any()) { var youngest = ancestors.OrderByDescending(a => a.Path.Depth).First(); formattedPath = ""; for (int i = 0; i <= dir.Path.Depth; i++) { if (i <= youngest.Path.Depth) { var identity = youngest.Path.IdentityAtDepth(i); if (identity.Length < 6) { identity += "\\"; } else { if (identity.Length > 5) { identity = $"{identity.Substring(0, 5)}~\\"; } } formattedPath += $"{identity}"; } else { formattedPath += $"{dir.Path.IdentityAtDepth(i)}\\"; } } } _formattedDirectories.Add(formattedPath, Size.BestFit(dir.TotalSize)); } }