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

Problem with File::Next::dirs and descend_filter #35

Open
pelagic opened this issue Aug 31, 2018 · 2 comments
Open

Problem with File::Next::dirs and descend_filter #35

pelagic opened this issue Aug 31, 2018 · 2 comments

Comments

@pelagic
Copy link

pelagic commented Aug 31, 2018

Hello Andy,

I use your Module File:Next very often in my daily work and I like it a lot!
I never used File::Next::dirs up to now and I think there might be a problem in that specific part of the code.

I need to read all directories within some top-level-diectories, but only one level down.
This is my setup:

find /tmp/A /tmp/B -type d
/tmp/A
/tmp/A/z
/tmp/A/z/0
/tmp/A/z/2
/tmp/A/z/1
/tmp/A/y
/tmp/A/x
/tmp/B
/tmp/B/d
/tmp/B/c
/tmp/B/b
/tmp/B/a

When I use this code:

my $iter = File::Next::dirs(
    { descend_filter => sub{0} }
  , @dirs
);
while ( defined (my $trovato = $iter->()) ) {
    say $trovato;
}

I get only the directories I used as parameter:

/tmp/A
/tmp/B

When I use

descend_filter => sub{1}

I get all directories down to the leaves (which is the expected behaviour here).

Am I missing something? Or is this a use case that is rarely used maybe?

Best regards,
Imre

Environment:

RHEL 7.0
perl v5.16.3
File::Next::VERSION : 1.12
@petdance
Copy link
Owner

I'm not understanding what you're seeing as wrong. In your first case, you're telling descend_filter to never descend, so you only get the starting points. In your second, you're telling descend_filter to always descend, so you get the entire tree. That makes sense to me.

What is it you were expecting differently?

@pelagic
Copy link
Author

pelagic commented Aug 31, 2018

I read the description here:

The descend filter is NOT applied to any directory names specified as @starting_points in the constructor.

This seems useful to me when I am looking for files only. So I can decide to search just the starting points or all deeper directories also.
Searching for directories, I see a need for a similar feature: I want to see either just the directories immediately within the starting points or I might be interested in all directories through all levels.

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

No branches or pull requests

2 participants