protected string FormattedJoinedDirectoriesUptTo(PathComponents comps, int amount, bool includeDrive = true) { if (!comps.HasDirectories || amount <= 0 || amount > comps.Directories.Length) { return(string.Empty); } return((includeDrive ? FormattedDrivePath(comps) : string.Empty) + string.Join(Path.DirectorySeparatorChar.ToString(), comps.Directories.Take(amount)) + Path.DirectorySeparatorChar.ToString()); }
protected IEnumerable <PathNode> Split(PathComponents comps) { LinkedList <PathNode> nodes = new LinkedList <PathNode>(); PathNode previousNode = null; PathNode currentNode = null; string nodeName = null; string nodePath = null; if (comps.HasDrive) { nodeName = FormattedDriveName(comps); nodePath = FormattedDrivePath(comps); currentNode = new PathNode(PathNode.TypeEnum.DRIVE, nodeName, nodePath, previousNode); previousNode = currentNode; nodes.AddLast(currentNode); // Include drive } if (comps.HasDirectories) { // Include ALL directories for (int i = 0; i < comps.Directories.Length; i++) { nodeName = comps.Directories.ElementAt(i); nodePath = FormattedJoinedDirectoriesUptTo(comps, i + 1); currentNode = new PathNode(PathNode.TypeEnum.FOLDER, nodeName, nodePath, previousNode); previousNode = currentNode; nodes.AddLast(currentNode); // Include directory } } if (comps.HasFileName) { nodeName = comps.FileName; nodePath = comps.FullPath; currentNode = new PathNode(PathNode.TypeEnum.FILE, nodeName, nodePath, previousNode); previousNode = currentNode; nodes.AddLast(currentNode); // Include file } return(nodes); }
protected string FormattedDrivePath(PathComponents comps) { return(comps.HasDrive ? comps.Drive + Path.VolumeSeparatorChar + Path.DirectorySeparatorChar : string.Empty); }
public PathNodes(string path) { Components = new PathComponents(path); Nodes = Split(Components); }