Open kpcyrd opened 2 years ago
For reference, using entry.path().file_name()
instead of entry.file_name()
seems to work.
fn is_hidden(entry: &walkdir::DirEntry) -> bool {
entry
.path()
.file_name()
.and_then(|file_name| file_name.to_str().map(|s| s.starts_with('.')))
.unwrap_or(false)
}
Path::new(".").file_name()
and Path::new("..").file_name()
return None
.
In this case, walkdir::DirEntry::file_name
returns the entire path, which is incorrectly determined to be a hidden file.
This is currently recommended to skip hidden directories in the docs:
This works well for
foo
, but breaks if.
is provided instead (playground):Output:
I'm wondering if
walkdir::FilterEntry
could be extended with a method to make the initial path skip the filter. Alternativelyis_hidden
could be enhanced to check for.
and..
sincefilter_entry
should never try these unless the path was the initial folder.The example code in the docs should be updated to include this change.
Thanks!