Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lucatrv opened this issue Feb 8, 2023 · 2 comments

Comments

@lucatrv
Copy link

lucatrv commented Feb 8, 2023

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.

@BurntSushi
Copy link
Owner

BurntSushi commented Feb 8, 2023

I'm fine with this, but only if it doesn't introduce new dependencies. And it should be Unicode aware. So hopefully this can be done with APIs in std, although it may involve allocs. I'm personally fine with that.

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.

I think this is fine.

@lucatrv
Copy link
Author

lucatrv commented Feb 8, 2023

@BurntSushi, thanks for your feedback, I issued PR #173 and #174, not sure why they did not pass CI tests...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants