Answer#
Whether readme.txt finds Readme.TXT depends on the file system, not on Rust:
- Windows (NTFS): names are case-preserving but compared without regard to case by default, so both spellings open the same file. Windows can mark individual folders case-sensitive, so this is a default, not a law.
- macOS: Apple's file system, APFS, is case-insensitive by default and can be formatted case-sensitive. A user can have either kind of volume.
- Linux (relevant when you ship to it too): usually case-sensitive.
This program writes Readme.TXT and opens it as readme.txt:
use std::fs;
fn main() -> std::io::Result<()> {
let dir = std::env::temp_dir().join("rs-forum-case-demo");
fs::create_dir_all(&dir)?;
fs::write(dir.join("Readme.TXT"), "hello")?;
// Same file on a case-insensitive file system; NotFound on a case-sensitive one.
match fs::read_to_string(dir.join("readme.txt")) {
Ok(t) => println!("readme.txt found: {t}"),
Err(e) => println!("readme.txt: {:?}", e.kind()),
}
fs::remove_dir_all(&dir)
}readme.txt found: helloWhat it means for your code:
- Do not decide "same file" with string equality. Two spellings can be one file, and on a case-sensitive volume two files that differ only by case can exist side by side.
- Keep the spelling the user typed or the system returned when you store a name, so it looks right when you show it again.
- Test on a case-sensitive volume if you ship to Linux or to Macs set up that way. Code that loads
Config.jsonasconfig.jsonworks on your Windows machine and fails there. - Do not create two names that differ only by case in your own folders (
Dataanddata); they collide on a case-insensitive volume.
Common mistakes#
- Hard-coding a file name in a different case from the one you ship.
- Using a case-insensitive comparison (for example
eq_ignore_ascii_case) on names for security checks. It is not the same as what the file system does for non-ASCII letters.
Related questions#
Can I ask the system whether a volume is case-sensitive?#
Yes, but the way differs per system and is not part of std. Check the platform's own documentation if you need it.
Sources#
- Microsoft, per-directory case sensitivity: https://learn.microsoft.com/windows/wsl/case-sensitivity (read 2026-12-05)
- Apple, About Apple File System: https://developer.apple.com/documentation/foundation/file_system/about_apple_file_system (read 2026-12-05)