BurntSushi/walkdir

Please add a method to walk entries in case-insensitive alphabetical order

Open

#172 建立於 2023年2月8日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Rust (125 fork)github user discovery
enhancementhelp wanted

倉庫指標

Star
 (1,504 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Considering a directory ./test with entries a B c D, the command ls test prints entries in alphabetical order regardless of case.

Instead the following code:

use walkdir::WalkDir;

fn main() {
    for entry in WalkDir::new("test").sort_by_file_name() {
        println!("{}", entry.unwrap().into_path().display());
    }
}

prints entries in the following order:

test
test\B
test\D
test\a
test\c

The reason is clear and is due to the sort method, however it took me some time to detect this behavior in a larger code where I was relying on actual alphabetical sorting.

Although one can easily implement case-insensitive alphabetical order using the lower level sort_by or sort_by_key methods, the existence of an additional sort_by_file_name_case_insensitive method would better clarify the two actual behaviors, and would probably be of wider use than sort_by_file_name.

If you agree I can issue a PR.

As an additional note, for performance reasons maybe it would be preferable to use the sort_unstable / sort_unstable_by / sort_unstable_by_key methods instead of the sort / sort_by / sort_by_key methods.

貢獻者指南