protected override void IndexFolder(FolderInfo dir, int level) { sbContent.AppendLine(GetFolderNameRow(dir, level)); foreach (FolderInfo subdir in dir.Folders) { if (config.AddEmptyLineAfterFolders) { sbContent.AppendLine(); } IndexFolder(subdir, level + 1); } if (dir.Files.Count > 0) { if (config.AddEmptyLineAfterFolders) { sbContent.AppendLine(); } foreach (FileInfo fi in dir.Files) { sbContent.AppendLine(GetFileNameRow(fi, level + 1)); } } }
protected override void IndexFolder(FolderInfo dir, int level = 0) { sbContent.AppendLine(GetFolderNameRow(dir, level)); string divClass = level > 0 ? "FolderBorder" : "MainFolderBorder"; sbContent.AppendLine(HtmlHelper.StartTag("div", "", "class=\"" + divClass + "\"")); if (dir.Files.Count > 0) { sbContent.AppendLine(HtmlHelper.StartTag("ul")); foreach (FileInfo fi in dir.Files) { sbContent.AppendLine(GetFileNameRow(fi, level)); } sbContent.AppendLine(HtmlHelper.EndTag("ul")); } foreach (FolderInfo subdir in dir.Folders) { IndexFolder(subdir, level + 1); } sbContent.AppendLine(HtmlHelper.EndTag("div")); }
protected override string GetFolderNameRow(FolderInfo dir, int level) { int heading = (level + 1).Between(1, 6); string folderInfoText = string.Empty; if (!dir.IsEmpty) { folderInfoText = dir.Size.ToSizeString(config.BinaryUnits) + " ("; if (dir.TotalFileCount > 0) { folderInfoText += dir.TotalFileCount + " file" + (dir.TotalFileCount > 1 ? "s" : ""); } if (dir.TotalFolderCount > 0) { if (dir.TotalFileCount > 0) { folderInfoText += ", "; } folderInfoText += dir.TotalFolderCount + " folder" + (dir.TotalFolderCount > 1 ? "s" : ""); } folderInfoText += ")"; folderInfoText = " " + HtmlHelper.Tag("span", folderInfoText, "", "class=\"folderinfo\""); } return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(dir.FolderName) + folderInfoText + HtmlHelper.EndTag("h" + heading); }
protected override void IndexFolder(FolderInfo dir, int level = 0) { xmlWriter.WriteStartElement("Folder"); if (config.UseAttribute) { xmlWriter.WriteAttributeString("Name", dir.FolderName); if (!dir.IsEmpty) xmlWriter.WriteAttributeString("Size", dir.Size.ToSizeString(config.BinaryUnits)); } else { xmlWriter.WriteElementString("Name", dir.FolderName); if (!dir.IsEmpty) xmlWriter.WriteElementString("Size", dir.Size.ToSizeString(config.BinaryUnits)); } if (dir.Files.Count > 0) { xmlWriter.WriteStartElement("Files"); foreach (FileInfo fi in dir.Files) { xmlWriter.WriteStartElement("File"); if (config.UseAttribute) { xmlWriter.WriteAttributeString("Name", fi.Name); xmlWriter.WriteAttributeString("Size", fi.Length.ToSizeString(config.BinaryUnits)); } else { xmlWriter.WriteElementString("Name", fi.Name); xmlWriter.WriteElementString("Size", fi.Length.ToSizeString(config.BinaryUnits)); } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); } if (dir.Folders.Count > 0) { xmlWriter.WriteStartElement("Folders"); foreach (FolderInfo subdir in dir.Folders) { IndexFolder(subdir); } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); }
protected override void IndexFolder(FolderInfo dir, int level = 0) { if (settings.CreateParseableJson) { IndexFolderParseable(dir, level); } else { IndexFolderSimple(dir, level); } }
private void IndexFolderSimple(FolderInfo dir, int level) { jsonWriter.WritePropertyName(dir.FolderName); jsonWriter.WriteStartArray(); foreach (FolderInfo subdir in dir.Folders) { jsonWriter.WriteStartObject(); IndexFolder(subdir); jsonWriter.WriteEndObject(); } foreach (FileInfo fi in dir.Files) { jsonWriter.WriteValue(fi.Name); } jsonWriter.WriteEnd(); }
protected FolderInfo GetFolderInfo(string folderPath, int level = 0) { FolderInfo folderInfo = new FolderInfo(folderPath); if (config.MaxDepthLevel == 0 || level < config.MaxDepthLevel) { try { DirectoryInfo currentDirectoryInfo = new DirectoryInfo(folderPath); foreach (DirectoryInfo directoryInfo in currentDirectoryInfo.EnumerateDirectories()) { if (config.SkipHiddenFolders && directoryInfo.Attributes.HasFlag(FileAttributes.Hidden)) { continue; } FolderInfo subFolderInfo = GetFolderInfo(directoryInfo.FullName, level + 1); folderInfo.Folders.Add(subFolderInfo); subFolderInfo.Parent = folderInfo; } foreach (FileInfo fileInfo in currentDirectoryInfo.EnumerateFiles()) { if (config.SkipHiddenFiles && fileInfo.Attributes.HasFlag(FileAttributes.Hidden)) { continue; } folderInfo.Files.Add(fileInfo); } folderInfo.Files.Sort((x, y) => x.Name.CompareTo(y.Name)); } catch (UnauthorizedAccessException) { } } return folderInfo; }
private void IndexFolderParseable(FolderInfo dir, int level) { jsonWriter.WritePropertyName("Name"); jsonWriter.WriteValue(dir.FolderName); if (settings.ShowSizeInfo) { jsonWriter.WritePropertyName("Size"); jsonWriter.WriteValue(dir.Size.ToSizeString(settings.BinaryUnits)); } if (dir.Folders.Count > 0) { jsonWriter.WritePropertyName("Folders"); jsonWriter.WriteStartArray(); foreach (FolderInfo subdir in dir.Folders) { jsonWriter.WriteStartObject(); IndexFolder(subdir); jsonWriter.WriteEndObject(); } jsonWriter.WriteEnd(); } if (dir.Files.Count > 0) { jsonWriter.WritePropertyName("Files"); jsonWriter.WriteStartArray(); foreach (FileInfo fi in dir.Files) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Name"); jsonWriter.WriteValue(fi.Name); if (settings.ShowSizeInfo) { jsonWriter.WritePropertyName("Size"); jsonWriter.WriteValue(fi.Length.ToSizeString(settings.BinaryUnits)); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEnd(); } }
private string GetFolderNameRow(FolderInfo dir, int level) { string folderNameRow = ""; if (!dir.IsEmpty) { if (settings.ShowSizeInfo) { folderNameRow += dir.Size.ToSizeString(settings.BinaryUnits) + " "; } folderNameRow += "("; if (dir.TotalFileCount > 0) { folderNameRow += dir.TotalFileCount + " file" + (dir.TotalFileCount > 1 ? "s" : ""); } if (dir.TotalFolderCount > 0) { if (dir.TotalFileCount > 0) { folderNameRow += ", "; } folderNameRow += dir.TotalFolderCount + " folder" + (dir.TotalFolderCount > 1 ? "s" : ""); } folderNameRow += ")"; folderNameRow = " " + HtmlHelper.Tag("span", folderNameRow, "", "class=\"FolderInfo\""); } int heading = (level + 1).Between(1, 6); return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(dir.FolderName) + folderNameRow + HtmlHelper.EndTag("h" + heading); }
private string GetFolderNameRow(FolderInfo dir, int level) { string folderNameRow = string.Format("{0}{1}", settings.IndentationText.Repeat(level), dir.FolderName); if (settings.ShowSizeInfo && dir.Size > 0) { folderNameRow += string.Format(" [{0}]", dir.Size.ToSizeString(settings.BinaryUnits)); } return folderNameRow; }
protected abstract void IndexFolder(FolderInfo dir, int level = 0);
protected virtual string GetFolderNameRow(FolderInfo dir, int level = 0) { string text = string.Format("{0}{1}", config.IndentationText.Repeat(level), dir.FolderName); if (dir.Size > 0) { text += string.Format(" [{0}]", dir.Size.ToSizeString(config.BinaryUnits)); } return text; }
protected override void IndexFolder(FolderInfo dir, int level = 0) { xmlWriter.WriteStartElement("Folder"); if (settings.UseAttribute) { xmlWriter.WriteAttributeString("Name", dir.FolderName); if (settings.ShowSizeInfo && !dir.IsEmpty) { xmlWriter.WriteAttributeString("Size", dir.Size.ToSizeString(settings.BinaryUnits)); } } else { xmlWriter.WriteElementString("Name", dir.FolderName); if (settings.ShowSizeInfo && !dir.IsEmpty) { xmlWriter.WriteElementString("Size", dir.Size.ToSizeString(settings.BinaryUnits)); } } if (dir.Files.Count > 0) { xmlWriter.WriteStartElement("Files"); foreach (FileInfo fi in dir.Files) { xmlWriter.WriteStartElement("File"); if (settings.UseAttribute) { xmlWriter.WriteAttributeString("Name", fi.Name); if (settings.ShowSizeInfo) { xmlWriter.WriteAttributeString("Size", fi.Length.ToSizeString(settings.BinaryUnits)); } } else { xmlWriter.WriteElementString("Name", fi.Name); if (settings.ShowSizeInfo) { xmlWriter.WriteElementString("Size", fi.Length.ToSizeString(settings.BinaryUnits)); } } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); } if (dir.Folders.Count > 0) { xmlWriter.WriteStartElement("Folders"); foreach (FolderInfo subdir in dir.Folders) { IndexFolder(subdir); } xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); }