1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Search for filenames within a directory.
//!
//! This module searches the filenames in a specified directory for
//! a substring. It is useful for checking whether files exist
//! whose full names are not known exactly.
/**
* search_file_directory.c
*
* (C) Copyright 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use fs;
use Path;
/// Checks whether a search term appears in the name of a file within a directory.
///
/// The function scans the directory flat (not recursively) and compares
/// each filename with the passed `search_string`.
///
/// # Arguments
/// * `directory` - The path to the directory to be searched (accepts `&str`, `PathBuf`, etc.).
/// * `search_string` - The string to search for in the filename.
///
/// # Return Value
/// * `Ok(true)` - At least one file contains the search term in its name.
/// * `Ok(false)` - No file matches the search criteria.
/// * `Err(std::io::Error)` - Error accessing the directory.
///
/// # Usage:
///
/// ```rust
/// fn main() {
/// let sources_dir = "./src";
/// let search_string = "helper";
/// match search_file_directory(sources_dir, search_string) {
/// Ok(true) => println!("File!"),
/// Ok(false) => println!("No file."),
/// Err(e) => eprintln!("Error: {}", e),
/// }
/// }
/// ```