Expand description
This module includes additional methods for working with directories.
One of the additional features is information about process and recursion operations.
§Example
ⓘ
use std::path::Path;
use std::{thread, time};
use std::sync::mpsc::{self, TryRecvError};
extern crate fs_extra;
use fs_extra::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 options = CopyOptions {
buffer_size: 1,
..Default::default(),
};
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();
}
Structs§
- Copy
Options - Options and flags which can be used to configure how a file will be copied or moved.
- DirContent
- A structure which include information about directory
- DirOptions
- LsResult
- Result returned by the
ls
function. - Transit
Process - A structure which include information about the current status of the copy or move directory.
Enums§
- DirEntry
Attr - Available attributes for get information about directory entry.
- DirEntry
Value - Available types for directory entry.
- Transit
Process Result - Available returns codes for user decide
- Transit
State
Functions§
- copy
- Copies the directory contents from one place to another using recursive method. This function will also copy the permission bits of the original files to destination files (not for directories).
- copy_
with_ progress - Copies the directory contents from one place to another using recursive method, with information about progress. This function will also copy the permission bits of the original files to destination files (not for directories).
- create
- Creates a new, empty directory at the provided path.
- create_
all - Recursively create a directory and all of its parent components if they are missing.
- get_
details_ entry - Returned information about directory entry with information which you choose in config.
- get_
dir_ content - Return DirContent which contains information about directory:
- get_
dir_ content2 - Return DirContent which contains information about directory:
- get_
size - Returns the size of the file or directory in bytes.(!important: folders size not count)
- ls
- Returns a collection of directory entries with attributes specifying the information that should be returned.
- move_
dir - Moves the directory contents from one place to another. This function will also copy the permission bits of the original files to destination files (not for directories).
- move_
dir_ with_ progress - Moves the directory contents from one place to another with information about progress. This function will also copy the permission bits of the original files to destination files (not for directories).
- remove
- Removes directory.