Crate file_access

Source
Expand description

This crate is a collection of utilities to make performing certain file manipulations more convenient.

§Examples

use file_access::AsFile;

fn main() -> std::io::Result<()> {
    Ok({
        let text = "Cargo.toml".as_file().read_string()?;
        println!("{}", text);

        "Cargo.toml".as_file().read_lines()?
            .iter()
            .for_each(|line| {
                println!("{}", line);
            });

        "file.1".as_file().write_string(&"Hello, World!")?;

        let file = "file.1".as_file();
        file.append_lines(&vec!["hello", "world"])?;
        file.copy_to(&"file.2")?; // copies ./file.1 to ./file.2

        "file.2".as_file().rename_to(&"file.1")?; // replace
        "file.1".as_file().delete()?; // clean-up
    })
}

Re-exports§

pub use as_file::*;
pub use file_path::*;

Modules§

as_file
file_path

Functions§

append_lines
Appends a list of text as lines to a file. This function will append the contents of the file, or write a new one and its full directory path if they don’t exist yet.
append_string
Appends text to a file. This function will append the contents of the file, or write a new one and its full directory path if they don’t exist yet.
copy
Copies the contents of a file and write it to a destination. This function will entirely replace the contents of the destination if it already exists.
delete
Deletes a file, or a directory recursively.
get_metadata
Queries metadata about the underlying file.
read_lines
Reads the contents of a file and returns it as lines.
read_string
Reads the contents of a file.
rename
Copies the contents of a file, writes it to a destination and then deletes the source. This function will entirely replace the contents of the destination if it already exists.
write_lines
Writes a list of text as lines to a file. This function will create the file and its full directory path if they don’t exist, and will entirely replace the contents with the provided strings each on its own line.
write_string
Writes text to a file. This function will create the file and its full directory path if they don’t exist, and will entirely replace the contents.