Module fs_extra::dir [] [src]

This module include extra methods for works with directories.

One of the distinguishing features is receipt information about process work with directories 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 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();
}

Structs

CopyOptions

Options and flags which can be used to configure how a file will be copied or moved.

DirContent

A structure which imclude information about directory

LsResult

Result returned by the ls function.

TransitProcess

A structure which include information about the current status of the copy or move directory.

Enums

DirEntryAttr

Available attributes for get information about directory entry.

DirEntryValue

Available types for directory entry.

TransitProcessResult

Available returns codes for user decide

TransitState

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 destionation files (not for directories).

copy_with_progress

Copies the directory contents from one place to another using recursive method, with recept information about process. This function will also copy the permission bits of the original files to destionation 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 containt information about directory:

get_size

Returns the size of the file or directory

ls

Returned collection directory entries with information which you choose in config.

move_dir

Moves the directory contents from one place to another. This function will also copy the permission bits of the original files to destionation files (not for directories).

move_dir_with_progress

Moves the directory contents from one place to another with recept information about process. This function will also copy the permission bits of the original files to destionation files (not for directories).

remove

Removes directory.