[][src]Struct fs_pro::Dir

pub struct Dir {
    pub path: PathBuf,
}

the Dir struct is a struct for helping you working with directories

Fields

path: PathBuf

the path of directory

Implementations

impl Dir[src]

pub fn new<'a, P: 'a + AsRef<Path>>(path: P) -> Result<Dir>[src]

creates a new Dir

use fs_pro::Dir;

let dir = Dir::new("/path/to/dir").unwrap();
let dir = Dir::new(Path::new("/path/to/dir")).unwrap();
let dir = Dir::new(PathBuf::from("/path/to/dir"));

Errors

  • given path is file
  • invalid path

pub fn temp_dir<'a, P: 'a + AsRef<Path>>(name: P) -> Result<Dir>[src]

creates a directory in the temp directory

use fs_pro::Dir;

let temp_dir = Dir::temp_dir("name").unwrap();

pub fn temp_dir_no_create<'a, P: 'a + AsRef<Path>>(name: P) -> Result<Dir>[src]

like temp_dir but doesn't create the directory

use fs_pro::Dir;

let temp_dir = Dir::temp_dir_no_create("name").unwrap();

pub fn temp_dir_rand() -> Result<Dir>[src]

create a directory in the temp directory with random name

use fs_pro::Dir;

let temp_dir = Dir::temp_dir_rand();

pub fn temp_dir_rand_no_create() -> Result<Dir>[src]

like temp_dir_rand but doesn't create the directory

use fs_pro::Dir;

let temp_dir = Dir::temp_dir_rand_no_create();

pub fn parent(&self) -> Result<&str>[src]

gets the parent of the directory in &str

use fs_pro::Dir;

let dir = Dir::temp_dir_rand().unwrap();
assert_eq!(dir.parent().unwrap(), "/tmp");

pub fn name(&self) -> Result<&str>[src]

gets the name of the directory in &str

use fs_pro::Dir;

let dir = Dir::temp_dir("my_dir").unwrap();
assert_eq!(dir.name().unwrap(), "my_dir");

pub fn parse_path(&self) -> Result<ParsedPathDir<'_>>[src]

parses the path and returns fs_pro::ParedPathDir

pub fn size(&self) -> Result<u64>[src]

get the size of directory in bytes

impl Dir[src]

pub fn exists(&self) -> bool[src]

return true if file exists

pub fn create(&self) -> Result<()>[src]

creates the directory if doesn't already exits

pub fn create_all(&self) -> Result<()>[src]

creates the directory and it's parent if doesn't exists

pub fn delete(&self) -> Result<()>[src]

delete the directory even if empty

pub fn create_file<P: AsRef<Path>>(&self, name: P) -> Result<File>[src]

create a file inside the directory and return fs_pro::File

let file = dir.create_file("hi.txt")?;
file.write("some thing")?;
// ...

pub fn create_dir<P: AsRef<Path>>(&self, name: P) -> Result<Dir>[src]

create a directory inside the directory and returns fs_pro::Dir

let sub_dir = dir.create_dir("sub_dir")?;
sub_dir.create_file("hello.txt")?;
// ...

pub fn delete_file<P: AsRef<Path>>(&self, name: P) -> Result<()>[src]

delete a file inside the directory

dir.delete_file("to_delete.txt")?;

pub fn delete_dir<P: AsRef<Path>>(&self, name: P) -> Result<()>[src]

delete a directory inside the directory

dir.delete_dir("sub_dir")?;

pub fn get_file<P: AsRef<Path>>(&self, name: P) -> Result<File>[src]

get a fs_pro::File inside the directory

let file = dir.get_file("my_file.txt")?;
file.create()?;
// ...

pub fn get_dir<P: AsRef<Path>>(&self, name: P) -> Result<Dir>[src]

get a fs_pro::Dir inside the directory

let sub_dir = dir.get_dir("sub_dir")?;
sub_dir.create()?;
// ...

pub fn copy<P: AsRef<Path>>(&self, to: P, options: &CopyOptions) -> Result<Dir>[src]

copy the directory and returns directory's copy fs_pro::Dir

let dir_copy = dir.copy("copy_path")?;
dir_copy.create_file("some_file")?;
// ...

pub fn copy_with_progress<P: AsRef<Path>, F: FnMut(TransitProcess) -> TransitProcessResult>(
    &self,
    to: P,
    options: &CopyOptions,
    progress_handler: F
) -> Result<Dir>
[src]

copy the directory with progress and returns directory's copy as fs_pro::Dir

extern crate fs_extra;
use fs_extra::dir::{CopyOptions, TransitProcess, TransitProcessResult};

let options = CopyOptions::new();
let handle = |process_info: TransitProcess|  {
   println!("{}", process_info.total_bytes);
   TransitProcessResult::ContinueOrAbort
}
let dir_copy = dir.copy_with_progress("dest_path", &options, handle)?;

pub fn move_to<P: AsRef<Path>>(
    &self,
    to: P,
    options: &CopyOptions
) -> Result<Dir>
[src]

moves the directory and returns directory as fs_pro::Dir

dir = dir.move("dest")?;
dir.create_file("some_file")?;
// ...

pub fn move_to_with_progress<P: AsRef<Path>, F: FnMut(TransitProcess) -> TransitProcessResult>(
    &self,
    to: P,
    options: &CopyOptions,
    progress_handler: F
) -> Result<Dir>
[src]

copy the directory with progress and returns directory's dest as fs_pro::Dir

extern crate fs_extra;
use fs_extra::dir::{CopyOptions, TransitProcess, TransitProcessResult};

let options = CopyOptions::new();
let handle = |process_info: TransitProcess|  {
   println!("{}", process_info.total_bytes);
   TransitProcessResult::ContinueOrAbort
}
dir = dir.move_with_progress("dest_path", &options, handle)?;

pub fn get_content(&self) -> Result<DirContent>[src]

return fs_extra::dir::DirContent which contains information about directory see https://docs.rs/fs_extra/1.1.0/fs_extra/dir/fn.get_dir_content.html

let dir_content = dir.get_content()?;
for directory in dir_content.directories {
  println!("{}", directory); // print directory path
}

pub fn get_content2(&self, options: &DirOptions) -> Result<DirContent>[src]

return fs_extra::dir::DirContent which contains information about directory see https://docs.rs/fs_extra/1.1.0/fs_extra/dir/fn.get_dir_content2.html

extern crate fs_extra;
use fs_extra::dir::DirOptions;

let options = DirOptions::new();
options.depth = 3; // Get 3 levels of folder.
let dir_content = get_dir_content2("dir", &options)?;
for directory in dir_content.directories {
   println!("{}", directory); // print directory path
}

pub fn get_details_entry(
    &self,
    config: &HashSet<DirEntryAttr>
) -> Result<HashMap<DirEntryAttr, DirEntryValue>>
[src]

returns information about directory entry with information which you choose in config see https://docs.rs/fs_extra/1.1.0/fs_extra/dir/fn.get_details_entry.html

extern crate fs_extra;
use fs_extra::dir::{DirEntryAttr};
use std::collections::{HashMap, HashSet};

let mut config = HashSet::new();
config.insert(DirEntryAttr::Name);
config.insert(DirEntryAttr::Size);

let entry_info = dir.get_details_entry(&config);
assert_eq!(2, entry_info.len());

pub fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<Dir>[src]

creates a directory inside directory and it's parent if missing

let sub_dir = dir.create_dir_all("foo/bar/some") // creates foo and bar and some

pub fn create_file_all<P: AsRef<Path>>(&self, path: P) -> Result<File>[src]

creates a file inside directory and it's parent if missing

let file = dir.create_file_all("foo/bar/some.txt") // creates foo and bar and some.txt

pub fn ls(&self, config: &HashSet<DirEntryAttr>) -> Result<LsResult>[src]

returns collection directory entries with information which you choose in config see https://docs.rs/fs_extra/1.1.0/fs_extra/dir/fn.ls.html

extern crate fs_extra;
use fs_extra::dir::DirEntryAttr;
use std::collections::HashSet;
let mut config = HashSet::new();
config.insert(DirEntryAttr::Name);
config.insert(DirEntryAttr::Size);
config.insert(DirEntryAttr::BaseInfo);

let result = dir.ls(&config);
assert_eq!(2, ls_result.items.len());
assert_eq!(2, ls_result.base.len());

pub fn read(&self) -> Result<Vec<DirEntry>>[src]

reads the folder

use fs_pro::DirEntry;
for entry in my_dir.read()? {
  match entry {
    DirEntry::File(file) => {
      println!("{:?} is a file", file.path)
    }
    DirEntry::Dir(dir) => {
      println!("{:?} is a folder", dir.path)
    }
  }
}

pub fn read_as_osstring_vec(&self) -> Result<Vec<OsString>>[src]

read the dir and return an array containing the file name of each entry as OsString

pub fn read_as_pathbuf_vec(&self) -> Result<Vec<PathBuf>>[src]

read the dir and return an array containing the full path of each entry as PathBuf

pub fn entry_exists<P: AsRef<Path>>(&self, path: P) -> bool[src]

checks if an entry (file or folder) exists in the dir

Trait Implementations

impl AsRef<Path> for Dir[src]

impl Clone for Dir[src]

impl Debug for Dir[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,