Crate fs_more

source ·
Expand description

Convenient file and directory operations built on top of std::fs with improved error handling. Includes copying / moving files and directories with progress reporting.

Main features

  • copying and moving files or directories with in-depth configuration options (including IO buffering settings, copying depth, etc.)
  • copying and moving files (or directories) with progress reporting,
  • scanning directories with depth and other options, and
  • calculating file or directory sizes.

To start off, visit the directory and file modules for more information and a list of functions.


Feature flags

The following feature flags are available:

  • fs-err: enables the optional fs-err support, enabling more helpful underlying IO error messages (though fs-more already provides many on its own).

Examples

Copying a file with a progress handler:

let source_path = Path::new("./source-file.txt");
let target_path = Path::new("./target-file.txt");

let copy_result = fs_more::file::copy_file_with_progress(
    source_path,
    target_path,
    FileCopyWithProgressOptions::default(),
    |progress| {
        let percent_copied =
            (progress.bytes_finished as f64) / (progress.bytes_total as f64)
            * 100.0;

        println!("Copied {:.2}% of the file!", percent_copied);
    }
)?;

Moving a directory with a progress handler:

let source_path = Path::new("./source-directory");
let target_path = Path::new("./target-directory");

let move_result = fs_more::directory::move_directory_with_progress(
    source_path,
    target_path,
    DirectoryMoveWithProgressOptions {
        target_directory_rule: TargetDirectoryRule::AllowEmpty,
        ..Default::default()
    },
    |progress| {
        let percent_moved =
            (progress.bytes_finished as f64) / (progress.bytes_total as f64)
            * 100.0;

        println!(
            "Moved {:.2}% of the directory ({} files and {} directories so far).",
            percent_moved,
            progress.files_moved,
            progress.directories_created
        );
    }
)?;

Attribution

Inspired by fs_extra

fs-more isn’t a fork, but has been inspired by some of the functionalities of the fs_extra library (thank you!).

Modules

  • Directory scanning, sizing, copying and moving operations. Includes progress monitoring variants.
  • Errors provided by this library.
  • File sizing, copying, moving and removal operations. Includes progress monitoring variants.