Function tauri::api::dir::is_dir

source ·
pub fn is_dir<P: AsRef<Path>>(path: P) -> Result<bool>
Expand description

Checks if the given path is a directory.

Examples found in repository?
src/api/dir.rs (line 69)
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
pub(crate) fn read_dir_with_options<P: AsRef<Path>>(
  path: P,
  recursive: bool,
  options: ReadDirOptions<'_>,
) -> crate::api::Result<Vec<DiskEntry>> {
  let mut files_and_dirs: Vec<DiskEntry> = vec![];
  for entry in fs::read_dir(path)? {
    let path = entry?.path();
    let path_as_string = path.display().to_string();

    if let Ok(flag) = is_dir(&path_as_string) {
      files_and_dirs.push(DiskEntry {
        path: path.clone(),
        children: if flag {
          Some(
            if recursive
              && (!is_symlink(&path_as_string)?
                || options.scope.map(|s| s.is_allowed(&path)).unwrap_or(true))
            {
              read_dir_with_options(&path_as_string, true, options)?
            } else {
              vec![]
            },
          )
        } else {
          None
        },
        name: path
          .file_name()
          .map(|name| name.to_string_lossy())
          .map(|name| name.to_string()),
      });
    }
  }
  Result::Ok(files_and_dirs)
}