Пример #1
0
        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());
        }
Пример #2
0
        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);
        }
Пример #3
0
 protected string FormattedDrivePath(PathComponents comps)
 {
     return(comps.HasDrive ? comps.Drive + Path.VolumeSeparatorChar + Path.DirectorySeparatorChar : string.Empty);
 }
Пример #4
0
 public PathNodes(string path)
 {
     Components = new PathComponents(path);
     Nodes      = Split(Components);
 }