Mega Code Archive

 
Categories / C# / File Stream
 

Class, which describes folder with its subfolders

using System.Collections.Generic; using System.IO; namespace MangaUtils {   /// <summary>   /// Class, which describes folder with its subfolders.   /// </summary>   public class Folder   {     /// <summary>     /// Absolute path to current folder     /// </summary>     public string Path;     /// <summary>     /// List of subfolders (if any).     /// </summary>     public List<Folder> Subfolders;     /// <summary>     /// Default constructor - nothing special, just initializing.     /// </summary>     public Folder()     {       Path = string.Empty;       Subfolders = new List<Folder>();     }     /// <summary>     /// Constructor which scans recursively given folder.     /// </summary>     /// <param name="path">Absolutte path to folder.</param>     public Folder(string path)     {       Path = path;       Subfolders = new List<Folder>();       var dirs = new List<string>(Directory.GetDirectories(path));       foreach (var dir in dirs)       {         var folder = new Folder(dir);         Subfolders.Add(folder);       }     }     /// <summary>     /// Overriden method, which returns name of current folder.     /// </summary>     /// <returns>Name of current folder.</returns>     public override string ToString()     {       int lastSlashPos = Path.LastIndexOf('\\');       var str = Path.Substring(lastSlashPos + 1);       return str;     }   } }