BurntSushi / walkdir

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

Contents first order issue #140

Open silasb opened 4 years ago

silasb commented 4 years ago

I have a folder structure like

$ find test/
test/
test/1.py
test/2a
test/2a/2.py
test/2a/2a.py
test/1a.py
test/2
test/2/2.py
test/2/2a.py
test/2/3
test/2/3/3.py

Doing

    for entry in WalkDir::new(t.input).contents_first(true) {
        let entry = entry.unwrap();
        println!("{}", entry.path().display());
   }

results in

test/1.py
test/2a/2.py
test/2a/2a.py
test/2a
test/1a.py
test/2/2.py
test/2/2a.py
test/2/3/3.py
test/2/3
test/2
test/

I'd expect to see

test/2/3/3.py
test/2/3
test/2a/2.py
test/2a/2a.py
test/2a
test/2/2.py
test/2/2a.py
test/2
test/1.py
test/1a.py
test/

per what the documentation is suggesting.

BurntSushi commented 4 years ago

The behavior is correct. The docs could be improved, probably with a better example. contents_first just changes when the entry for the directory itself is returned. It doesn't cause traversal to visit the deepest nodes first.

silasb commented 4 years ago

Thanks, that makes sense. I ended up solving my problem a different way. Do you want me to close this ticket?