BurntSushi / walkdir

Rust library for walking directories recursively.
The Unlicense
1.3k stars 109 forks source link

Simple filter_entry question #121

Closed cyberpunkbln closed 5 years ago

cyberpunkbln commented 5 years ago

Hello,

i will use your crate to filter all files with an extensions in an directory recursive. This are first steps with your crate:):


fn show(entry: &DirEntry) -> bool
    {
            println!("{:?}", entry.file_name().to_str().map(|s| s.ends_with(".exe")).unwrap());
        entry.file_name().to_str().map(|s| s.ends_with(".exe")).unwrap()
     }
for entry in walker.filter_entry(|e| show(e))
    {
        let entry = entry.unwrap();
        println!("{}", entry.path().display());
    }

I think for me that the filter_entry only shows all entries that will be come true in the fn show? When i say !show(e) then he shows correctly all files that are not exe, but when in the code above he shows nothing?

thx

BurntSushi commented 5 years ago

Sorry but i don't understand your question. Please provide a complete but minimal example of the code you're using. It should be a compilable and runnable program. Please then provide your input, along with the actual output and the expected output.

cyberpunkbln commented 5 years ago

i have solved my problem, not the walkdir way with filter_entry but it does what it does;).

for entry in WalkDir::new("c:\").into_iter().filter_map(|e| e.ok())
    {
        let testlnk = entry.file_name().to_str().map(|s| s.ends_with(".exe")).unwrap_or(false);
        if (testlnk)
        {

            println!("{}", entry.path().display());
        }
    }

A little bit hacky:).

I want only reveive a list with files that have an special ending like exe. Andir *.exe /s in rust :).

BurntSushi commented 5 years ago

I'm glad you solved it. In the future, when filing bug reports or asking questions, please make sure to provide a complete compilable/runnable example, along with input, actual output and expected output.