コード例 #1
0
 /// <summary>
 /// Collapses a <see cref="FilePath"/> containing ellipses.
 /// </summary>
 /// <returns>A collapsed <see cref="FilePath"/>.</returns>
 public FilePath Collapse()
 {
     return(new FilePath(PathCollapser.Collapse(this)));
 }
コード例 #2
0
ファイル: Globber.cs プロジェクト: natificent/cake
        private List <Path> Walk(DirectoryPath rootPath, Stack <Node> segments)
        {
            var results = new List <Path>();
            var segment = segments.Pop();

            var expression          = new Regex("^" + segment.Render() + "$", _options);
            var isDirectoryWildcard = false;

            if (segment is WildcardSegmentNode)
            {
                segments.Push(segment);
                isDirectoryWildcard = true;
            }

            // Get all files and folders.
            var root = _fileSystem.GetDirectory(rootPath);

            if (!root.Exists)
            {
                return(results);
            }
            var rootFullPath = PathCollapser.Collapse(rootPath);

            foreach (var directory in root.GetDirectories("*", SearchScope.Current))
            {
                var part     = directory.Path.FullPath.Substring(rootFullPath.Length + 1);
                var pathTest = expression.IsMatch(part);

                var subWalkCount = 0;

                if (isDirectoryWildcard)
                {
                    // Walk recursivly down the segment.
                    var nextSegments  = new Stack <Node>(segments.Reverse());
                    var subwalkResult = Walk(directory.Path, nextSegments);
                    if (subwalkResult.Count > 0)
                    {
                        results.AddRange(subwalkResult);
                    }

                    subWalkCount++;
                }

                // Check without directory wildcard.
                if (segments.Count > subWalkCount && (subWalkCount == 1 || pathTest))
                {
                    // Walk the next segment in the list.
                    var nextSegments  = new Stack <Node>(segments.Skip(subWalkCount).Reverse());
                    var subwalkResult = Walk(directory.Path, nextSegments);
                    if (subwalkResult.Count > 0)
                    {
                        results.AddRange(subwalkResult);
                    }
                }

                // Got a match?
                if (pathTest && segments.Count == 0)
                {
                    results.Add(directory.Path);
                }
            }

            foreach (var file in root.GetFiles("*", SearchScope.Current))
            {
                var part     = file.Path.FullPath.Substring(rootFullPath.Length + 1);
                var pathTest = expression.IsMatch(part);

                // Got a match?
                if (pathTest && segments.Count == 0)
                {
                    results.Add(file.Path);
                }
                else if (pathTest)
                {
                    /////////////////////////////////////////////////////////////B
                    // We got a match, but we still have segments left.
                    // Is the next part a directory wild card?
                    /////////////////////////////////////////////////////////////

                    var nextNode = segments.Peek();
                    if (nextNode is WildcardSegmentNode)
                    {
                        var nextSegments  = new Stack <Node>(segments.Skip(1).Reverse());
                        var subwalkResult = Walk(root.Path, nextSegments);
                        if (subwalkResult.Count > 0)
                        {
                            results.AddRange(subwalkResult);
                        }
                    }
                }
            }
            return(results);
        }
コード例 #3
0
 /// <summary>
 /// Collapses a <see cref="DirectoryPath"/> containing ellipses.
 /// </summary>
 /// <returns>A collapsed <see cref="DirectoryPath"/>.</returns>
 public DirectoryPath Collapse()
 {
     return(new DirectoryPath(PathCollapser.Collapse(this)));
 }