Module fs_extra::dir

source ·
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

Options and flags which can be used to configure how a file will be copied or moved.
A structure which include information about directory
Result returned by the ls function.
A structure which include information about the current status of the copy or move directory.

Enums

Available attributes for get information about directory entry.
Available types for directory entry.
Available returns codes for user decide

Functions

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).
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).
Creates a new, empty directory at the provided path.
Recursively create a directory and all of its parent components if they are missing.
Returned information about directory entry with information which you choose in config.
Return DirContent which contains information about directory:
Return DirContent which contains information about directory:
Returns the size of the file or directory in bytes.(!important: folders size not count)
Returns a collection of directory entries with attributes specifying the information that should be returned.
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).
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).
Removes directory.