mmv_lib/
finder.rs

1#![forbid(unsafe_code)]
2
3use crate::error_handler::Error;
4use std::{fs, path::Path};
5
6pub fn get_file_names_in_directory(directory: &Path) -> Result<Vec<String>, Error> {
7    let mut found_file_names = Vec::<String>::new();
8
9    for entry in fs::read_dir(directory)? {
10        let path = entry?.path();
11
12        if path.is_dir() {
13            continue;
14        }
15
16        if let Some(os_path) = path.file_name() {
17            found_file_names.push(os_path.to_str().unwrap().to_string());
18        }
19    }
20
21    match found_file_names.is_empty() {
22        true => Err(Error::NoFilesFound),
23        false => Ok(found_file_names),
24    }
25}