file-mon 0.1.0

Filesystem Monitoring
Documentation
use std::fs;
use std::path::Path;

/// Count the number of folders in a directory recursively.
///
/// # Arguments
///
/// * `path` - A reference to a `Path` representing the directory to count folders for.
///
/// # Returns
///
/// The number of folders found in the directory and its subdirectories.
///
/// # Example
///
/// ```
/// use file_mon::count_folders;
/// use std::path::Path;
///
/// let path = Path::new("/path/to/your/directory");
/// let folder_count = count_folders(path);
/// println!("Number of folders: {}", folder_count);
/// ```
pub fn count_folders(path: &Path) -> u32 {
    let mut folder_count = 0;

    if let Ok(entries) = fs::read_dir(path) {
        for entry in entries {
            if let Ok(entry) = entry {
                let metadata = entry.metadata().unwrap(); // Unwrap is safe here for simplicity

                if metadata.is_dir() {
                    folder_count += 1;
                    folder_count += count_folders(&entry.path()); // Recursively count subfolders
                }
            }
        }
    }

    folder_count
}