A Rust library for more work functionality with file system.
Copy files (optionally with information about the progress).
Copy directories recursively (optionally with information about the progress).
Move files (optionally with information about the progress).
Move directories recursively (optionally with information about the progress).
One method for create and write String
content in file.
One method for open and read String
content from file.
Get size folder
| Function | Description |
| ------------- | ------------- |
| fsextra::copyitems | Copies list directories and files to another place using recursive method |
| fsextra::copyitemswithprogress | Copies list directories and files to another place using recursive method, with recept information about process |
| fsextra::moveitems | Moves list directories and files to another place using recursive method |
| fsextra::moveitemswithprogress | Moves list directories and files to another place using recursive method, with recept information about process |
| fsextra::removeitems | Removes list files or directories |
| fsextra::fs::copy | Copies the contents of one file to another |
| fsextra::fs::copywithprogress | Copies the contents of one file to another with recept information about process |
| fsextra::fs::movefile | Moves file from one place to another |
| fsextra::fs::movefilewithprogress | Moves file from one place to another with recept information about process |
| fsextra::fs::remove | Removes a file from the filesystem |
| fsextra::fs::readtostring | Read file content, placing him into String
|
| fsextra::fs::writeall | Write String
content into inside target file |
| fsextra::dir::create | Creates a new, empty directory at the provided path |
| fsextra::dir::createall | Recursively create a directory and all of its parent components if they are missing |
| fsextra::dir::copy | Copies the directory contents from one place to another using recursive method |
| fsextra::dir::copywithprogress | Copies the directory contents from one place to another using recursive method, with recept information about process]() |
| fsextra::dir::movedir | Moves the directory contents from one place to another |
| fsextra::dir::movedirwithprogress | Moves the directory contents from one place to another with recept information about process |
| fsextra::dir::remove | Removes directory |
| fsextra::dir::getsize | Returns the size of the file or directory |
| fsextra::dir::getdir_content | Return DirContent which containt information about directory |
| fsextra::dir::getdetailsentry | Returned information about directory entry with information which you choose in config | | fsextra::dir::ls | Returned collection directory entries with information which you choose in config |
Add this to your Cargo.toml
:
toml
[dependencies]
fs_extra = "0.3.0"
and this to your crate root:
rust
extern crate fs_extra;
The following example shows how to copy a directory recursively and to follow the process.
This example created a directory dir
contains test1.txt
file and sub directory sub
. Folder sub
inside contains test2.txt
file.
Then copy ./temp/dir
and all containts to ./out/dir
```rust use std::path::Path; use std::{thread, time}; use std::sync::mpsc::{self, TryRecvError};
extern crate fsextra; use fsextra::dir::; use fs_extra::error::;
fn example_copy() -> Result<()> {
let path_from = Path::new("./temp");
let path_to = path_from.join("out");
let test_folder = path_from.join("test_folder");
let dir = test_folder.join("dir");
let sub = dir.join("sub");
let file1 = dir.join("file1.txt");
let file2 = sub.join("file2.txt");
create_all(&sub, true)?;
create_all(&path_to, true)?;
fs_extra::file::write_all(&file1, "content1")?;
fs_extra::file::write_all(&file2, "content2")?;
assert!(dir.exists());
assert!(sub.exists());
assert!(file1.exists());
assert!(file2.exists());
let mut options = CopyOptions::new();
options.buffer_size = 1;
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let handler = |process_info: TransitProcess| {
tx.send(process_info).unwrap();
thread::sleep(time::Duration::from_millis(500));
};
copy_with_progress(&test_folder, &path_to, &options, handler).unwrap();
});
loop {
match rx.try_recv() {
Ok(process_info) => {
println!("{} of {} bytes",
process_info.copied_bytes,
process_info.total_bytes);
}
Err(TryRecvError::Disconnected) => {
println!("finished");
break;
}
Err(TryRecvError::Empty) => {}
}
}
Ok(())
} fn main() { example_copy();
```