pub struct Filesystem;Expand description
Stateless host-filesystem operations.
All methods are free functions on &Path. There is no instance state.
Matches the surface of oa::Filesystem in C++ and its Python bindings so
that cross-language code reads identically:
Filesystem::create_directories(output.parent().unwrap())?;
let text = Filesystem::read_text(&config_path)?;Implementations§
Source§impl Filesystem
impl Filesystem
Sourcepub fn exists(path: &Path) -> bool
pub fn exists(path: &Path) -> bool
Return true if path exists (file, directory, or symlink target).
Sourcepub fn is_directory(path: &Path) -> bool
pub fn is_directory(path: &Path) -> bool
Return true if path is a directory.
Sourcepub fn get_file_size(path: &Path) -> Result<u64>
pub fn get_file_size(path: &Path) -> Result<u64>
Return the byte size of the file at path.
Sourcepub fn get_last_modified(path: &Path) -> Result<i64>
pub fn get_last_modified(path: &Path) -> Result<i64>
Return the last-modified time as seconds since the Unix epoch.
Matches oa::Filesystem::getLastModified which returns an i64 Unix
timestamp.
Sourcepub fn create_directory(path: &Path) -> Result<()>
pub fn create_directory(path: &Path) -> Result<()>
Create a single directory. Succeeds silently if it already exists.
Sourcepub fn create_directories(path: &Path) -> Result<()>
pub fn create_directories(path: &Path) -> Result<()>
Create a directory and all missing ancestors. Succeeds silently if the full path already exists as a directory.
Sourcepub fn remove_file(path: &Path) -> Result<()>
pub fn remove_file(path: &Path) -> Result<()>
Remove a file. Succeeds silently if the file does not exist.
Sourcepub fn remove_directory(path: &Path, recursive: bool) -> Result<()>
pub fn remove_directory(path: &Path, recursive: bool) -> Result<()>
Remove a directory.
When recursive is false the directory must be empty. When true
the entire subtree is removed. Succeeds silently if the path does not
exist.
Sourcepub fn copy(from: &Path, to: &Path) -> Result<()>
pub fn copy(from: &Path, to: &Path) -> Result<()>
Copy a file or directory.
For a directory, creates the destination directory (non-recursive). For a file, reads the source and writes it to the destination, creating parent directories as needed.
Sourcepub fn move_path(from: &Path, to: &Path) -> Result<()>
pub fn move_path(from: &Path, to: &Path) -> Result<()>
Move (rename) a path. Creates parent directories of the destination.
Note: cannot be named move in Rust (reserved keyword).
Sourcepub fn list_files(dir: &Path, extension: &str) -> Result<Vec<PathBuf>>
pub fn list_files(dir: &Path, extension: &str) -> Result<Vec<PathBuf>>
List regular files in dir, optionally filtered by extension.
extension is matched against the full extension string including the
leading . (e.g. ".png"). Pass "" to return all files.
Results are sorted lexicographically.
Sourcepub fn list_directories(dir: &Path) -> Result<Vec<PathBuf>>
pub fn list_directories(dir: &Path) -> Result<Vec<PathBuf>>
List immediate sub-directories of dir. Symlinks are not followed.
Results are sorted lexicographically.
Sourcepub fn list_all(dir: &Path, recursive: bool) -> Result<Vec<PathBuf>>
pub fn list_all(dir: &Path, recursive: bool) -> Result<Vec<PathBuf>>
List all entries (files and directories) in dir.
When recursive is true, descends into sub-directories but does not
follow symlinks. Results are sorted lexicographically.
Sourcepub fn write_text(path: &Path, content: &str) -> Result<()>
pub fn write_text(path: &Path, content: &str) -> Result<()>
Write content to a file, creating parent directories as needed.
Truncates any existing content.
Sourcepub fn append_text(path: &Path, content: &str) -> Result<()>
pub fn append_text(path: &Path, content: &str) -> Result<()>
Append content to a file, creating parent directories as needed.
Sourcepub fn read_lines(path: &Path) -> Result<Vec<String>>
pub fn read_lines(path: &Path) -> Result<Vec<String>>
Read lines, stripping \r\n and \n line endings. The final line is
included even if it lacks a trailing newline. Empty files return an
empty Vec.
Sourcepub fn write_binary(path: &Path, data: &[u8]) -> Result<()>
pub fn write_binary(path: &Path, data: &[u8]) -> Result<()>
Write data to a file, creating parent directories as needed.
Truncates any existing content.