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

fix: Support relative paths with multiple subfolders in Directory.GetFiles #332

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static string GetSubdirectoryPath(this IFileSystem fileSystem,
return fullFilePath;
}

string currentDirectory = fileSystem.Directory.GetCurrentDirectory();
string currentDirectory = fileSystem.Path.GetFullPath(givenPath);
if (currentDirectory == string.Empty.PrefixRoot())
{
fullFilePath = fullFilePath.Substring(currentDirectory.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ public abstract partial class GetFilesTests<TFileSystem>
: FileSystemTestBase<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableTheory]
[AutoData]
public void GetFiles_WithRelativePathAndSubfolders_ShouldReturnRelativeFilePath(string subfolder1, string subfolder2, string[] files)
{
string workingDirectory = System.IO.Path.Combine(BasePath, subfolder1, subfolder2);
FileSystem.Directory.CreateDirectory(workingDirectory);
foreach (string file in files)
{
FileSystem.File.Create(System.IO.Path.Combine(workingDirectory, file));
}

FileSystem.Directory.SetCurrentDirectory($@".\{subfolder1}");
vbreuss marked this conversation as resolved.
Show resolved Hide resolved
var result = FileSystem.Directory.GetFiles($@"..\{subfolder1}\{subfolder2}").ToList();

IEnumerable<string> expectation = files.Select(f => System.IO.Path.Combine("..", subfolder1, subfolder2, f));
result.Should().BeEquivalentTo(expectation);
}

[SkippableTheory]
[AutoData]
public void
Expand Down