read the directory and sort the entries by the alphabet oder
(dir: &Path)
| 642 | |
| 643 | /// read the directory and sort the entries by the alphabet oder |
| 644 | pub fn read_sort_dir(dir: &Path) -> Result<Vec<PathBuf>> { |
| 645 | let mut entries = Vec::new(); |
| 646 | if !dir.exists() { |
| 647 | return Ok(entries); |
| 648 | } |
| 649 | if !dir.is_dir() { |
| 650 | eyre::bail!("{dir:?} is not a directory") |
| 651 | } |
| 652 | for entry in std::fs::read_dir(dir)? { |
| 653 | let path = entry?.path(); |
| 654 | entries.push(path); |
| 655 | } |
| 656 | entries.sort(); |
| 657 | Ok(entries) |
| 658 | } |
| 659 | |
| 660 | pub fn is_dir_empty(dir: &Path) -> Result<bool> { |
| 661 | read_sort_dir(dir).map(|entries| entries.is_empty()) |