std::fs: cross-platform filesystem operations in Rust
Answer: The std::fs module contains basic methods to manipulate the contents of the local filesystem. Those methods represent cross-platform operations. Extra platform-specific functionality lives in extension traits. Many operations are subject to TOCTOU race conditions.
What the module covers
Basic methods for changing the contents of the local filesystem live in this module.
All methods in this module represent cross-platform filesystem operations.
Platform-specific extras appear on extension traits for the module's types.
A TOCTOU race, short for Time of Check to Time of Use, can affect many of these operations.
Everyday helpers in Rust By Example
Several functions in the module deal with the filesystem.
A simple implementation of cat, echo, or touch can use these functions on a path.
Recursively create a directory; the call returns io::Result.
See also
Claims
- id: C1 claim: std::fs has basic methods to manipulate the local filesystem. source: S1 evidence: "basic methods to manipulate the contents of the local"
- id: C2 claim: Those methods represent cross-platform filesystem operations. source: S1 evidence: "cross-platform filesystem operations"
- id: C3 claim: Many operations are subject to TOCTOU race conditions. source: S1 evidence: "Time of Check to Time of Use"
- id: C4 claim: The module contains several functions that deal with the filesystem. source: S2 evidence: "several functions that deal with the filesystem"
Sources
- [S1] std::fs. Rust Standard Library. https://doc.rust-lang.org/std/fs/index.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] Filesystem Operations. Rust By Example. https://doc.rust-lang.org/rust-by-example/std_misc/fs.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Rust Standard Library, std::fs; Rust By Example, Filesystem Operations. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Rust Standard Library, std::fs; Rust By Example, Filesystem Operations. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "std::fs: cross-platform filesystem operations in Rust." iinventedlight Library, iil:note:6btc36fk, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-fs/. License: CC-BY-4.0.
@misc{iil_note_6btc36fk,
author = {{iinventedlight}},
title = {{std::fs: cross-platform filesystem operations in Rust}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-fs/},
note = {Permanent ID iil:note:6btc36fk. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-fs.schema.json (schema; CC-BY-4.0)
- rust-fs.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-fs.md.