BurntSushi / walkdir

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

`sort_by_file_name` doesn't appear to be working #182

Open ShayBox opened 1 year ago

ShayBox commented 1 year ago
let paths = WalkDir::new(current_dir)
        .sort_by_file_name()
        .into_iter()
        .filter_map(Result::ok)
        .map(DirEntry::into_path)
        .collect::<Vec<_>>();

This leads to the outcome being random every time the program is run

EDIT: I'm on Windows 11 22H2 (22621.1778) using the latest stable Rust and walkdir

BurntSushi commented 1 year ago

Can you provide a full reproduction? Otherwise this might be something you'll have to debug on your own.

keyle commented 1 year ago

@ShayBox it might be because you're thinking that it sorts by file name, while in fact, it sorts by sub-folder first (by full path).

This got me confused as well at first, and ended up here, then I realised that even though it says by_file_name, it's really by_path_alphabetical.

HTH.