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

A file which matches the pattern in multiple ways is returned multiple times #52

Closed
robvanuden opened this issue Jul 2, 2019 · 5 comments
Labels

Comments

@robvanuden
Copy link

robvanuden commented Jul 2, 2019

Suppose I have the following file:
C:\files\a\a\a\b.txt
When I use the following code:
string[] matchingFiles = Glob.Files(@"C:\files", "**/a/**/b.txt").ToArray();
matchingFiles result is:

[0] = a\a\a\b.txt
[1] = a\a\a\b.txt
[2] = a\a\a\b.txt

When I add another a\ subfolder, it gets another item added etc.

Is this by design? I would rather get distinct values.

@kthompson
Copy link
Owner

No this is definitely not intentional. I will see if i can determine the cause.

@robvanuden
Copy link
Author

robvanuden commented Jul 4, 2019

@kthompson I'm new to this code, but when I append .Distinct() to this line it's working correctly.

I think when you want to fix this thoroughly, the code needs a serious refactoring.

Not sure what you want, so haven't created a PR (yet)...

@kthompson
Copy link
Owner

That would be one way to solve it but I am wondering if there is a way to prevent the traversal.

How would you suggest refactoring that would enable PathTraverser to prevent traversals that result in duplicate results?

@kthompson kthompson added the bug label Jul 4, 2019
@kthompson kthompson added this to the 2.0 milestone Mar 11, 2020
@ffMathy
Copy link

ffMathy commented Jun 27, 2020

How about just using a HashSet<string> to store the paths? That way, duplicates won't be stored, and it's O(1) insertion time complexity (almost no cost).

@kthompson kthompson removed this from the 2.0 milestone Jul 3, 2020
@kthompson
Copy link
Owner

Fixed in version 1.1.7

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

No branches or pull requests

3 participants