Working with files and directories
Modules
Structs
Options for how the file should be opened.
A filesystem path segment
Iterator over the segments of a path
Utility for creating directories.
A filesystem path
A file.
Iterator over the items in a directory
An owned (heap-allocated) path buffer
Directory entry
File attributes (
stat
)
Functions
-
Create an empty directory
See also DirBuilder for creating directories with more options (e.g. recursively).
-
Remove a file
Example
use std::fs::{File, Path, remove_file}; let filename = Path::new("foo.txt"); // Create an empty file File::create(filename).unwrap().close().unwrap(); // Remove the file remove_file(filename).unwrap();
Run this example -
Remove an empty directory
-
fn read_directory(path: Path) -> Result<DirIterator>
Returns iterator over the items in a directory.
See DirEntry for the item returned.
Example
use std::fs::{Path, read_directory}; let dir = read_directory(Path::new(".")).unwrap(); defer dir.close(); for item in dir { let item = item.unwrap(); println!("{}: {}", item.name(), item.file_type()); }
Run this example -
Returns a canonical absolute path for the given path.
Example
use std::fs::{Path, canonicalize}; let cwd = Path::new(".").canonicalize().unwrap(); defer cwd.free(); println!("Current directory: {}", cwd);
Run this example
Enums
Type of the path segment
Type of the file (regular file, symlink, directory, ...)