Expand description
Convenient file and directory operations built on top of std::fs
with improved error handling and in-depth configuration.
Includes copying or moving files and directories with progress reporting.
§Main features
- copy and move files or directories with:
- in-depth configuration options (existing destination file behaviour, copying depth, IO buffer sizes, etc.), and
- progress reporting, if wanted,
- scan directories (with options such as scan depth and symlink behaviour), and
- calculate file or directory sizes.
Visit the directory
and file
modules
for a deeper overview of the available features.
Additionally, you can find the error types in the error
module.
§Feature flags
|
---|
Enables the optional support for This feature is enabled by default — and highly recommended — because path canonicalization on Windows very commonly returns UNC paths.
|
|
---|
Enables the optional support for |
§Examples
Copying a file and getting updates on the progress:
let source_path = Path::new("./source-file.txt");
let destination_path = Path::new("./target-file.txt");
let finished_copy = fs_more::file::copy_file_with_progress(
source_path,
destination_path,
FileCopyWithProgressOptions {
colliding_file_behaviour: CollidingFileBehaviour::Abort,
..Default::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);
}
)?;
match finished_copy {
FileCopyFinished::Created { bytes_copied } => {
println!("Copied {bytes_copied} bytes!");
}
FileCopyFinished::Overwritten { bytes_copied } => {
println!("Copied {bytes_copied} bytes over an existing file!");
}
// ...
_ => {}
};
Moving a directory and getting updates on the progress:
let source_path = Path::new("./source-directory");
let destination_path = Path::new("./target-directory");
let moved = fs_more::directory::move_directory_with_progress(
source_path,
destination_path,
DirectoryMoveWithProgressOptions {
destination_directory_rule: DestinationDirectoryRule::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
);
}
)?;
println!(
"Moved {} bytes ({} files, {} directories)! Underlying strategy: {:?}.",
moved.total_bytes_moved,
moved.files_moved,
moved.directories_moved,
moved.strategy_used
);