Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make easier to search files in a certain directory #2056

Open
Kralizek opened this issue Feb 24, 2018 · 3 comments
Open

Make easier to search files in a certain directory #2056

Kralizek opened this issue Feb 24, 2018 · 3 comments

Comments

@Kralizek
Copy link

@Kralizek Kralizek commented Feb 24, 2018

I often find myself in the situation of looking for files matching a certain pattern within a folder or below.

Here is a typical use case

As of today, executing dotnet test on a solution will try to find and execute tests on every project filling the log with errors because no testable project was found. This is why I prefer to find every project file within the tests directory hive.

Task("Test")
    .IsDependentOn("Build")
    .Does(() => 
{
    var testProjects = FindFilesInDirectory(testDirectory, "*.csproj", SearchScope.Recursive);

    foreach (var project in testProjects)
    {
        DotNetCoreTest(project.FullPath);
    }
});

I am aware that the same functionality is offered by IFileSystem but the result of IFileSystem.GetFiles is a list of IFile instead of FilePath. This is not convenient since most of the aliases work with FilePath.

@Kralizek
Copy link
Author

@Kralizek Kralizek commented Feb 24, 2018

@patriksvensson
Copy link
Member

@patriksvensson patriksvensson commented Feb 24, 2018

@Kralizek Great!

The name indicates that it returns files and not file paths. Perhaps it should be renamed to something like GetFilePaths instead?

I'm also curious to why this method takes a DirectoryPath, pattern and SearchScope instead of a glob pattern, such as $"{testDirectory}/**/*.csproj". This would be more constistent with the GetFiles alias that already exist.

@devlead: What is your opinion?

@Kralizek
Copy link
Author

@Kralizek Kralizek commented Feb 24, 2018

I didn't like that I had to write GetFiles(testDirectory.FullPath + "/**/*.csproj"), but I didn't know that GetFiles($"{testDirectory}/**/*.csproj") is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants