예제 #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);
 }