pub fn find_entry_in_dir(dir_path: &Path, target: &Path) -> std::io::Result<Option<PathBuf>> {
    for entry in dir_path.read_dir()? {
        if let Ok(entry) = entry {
            // If it is a file with that same _filename_ (not full path)
            if entry.path().is_file() && entry.file_name() == target {
                return Ok(Some(entry.path().into()));
            } else if entry.path().is_dir() {
                // I think if there are any dirs on that directory we have to
                // recursively search on them
                if let Some(result) = find_entry_in_dir(&entry.path(), target)? {
                    return Ok(Some(result));
                }
            }
        }
    }
    Ok(None)
}
// Returns the first entry on that directory whose filename is equal to target.
//
// This spec is what makes me believe the search is recursive:
// https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
// This other one does not give that idea:
// https://specifications.freedesktop.org/menu-spec/latest/ar01s02.html
Returns the first entry on that directory whose filename is equal to target.
Returns the first entry on that directory whose filename is equal to target .
pub fn find_entry_in_dir(dir_path: &Path, target: &Path) -> std::io::Result<Option<PathBuf>> {
    for entry in dir_path.read_dir()? {
        if let Ok(entry) = entry {
            // If it is a file with that same _filename_ (not full path)
            if entry.path().is_file() && entry.file_name() == target {
                return Ok(Some(entry.path().into()));
            } else if entry.path().is_dir() {
                // I think if there are any dirs on that directory we have to
                // recursively search on them
                if let Some(result) = find_entry_in_dir(&entry.path(), target)? {
                    return Ok(Some(result));
                }
            }
        }
    }
    Ok(None)
}
pub fn find_entry_in_dir ( dir_path : & Path , target : & Path ) -> std :: io :: Result < Option < PathBuf > > { for entry in dir_path . read_dir ( ) ? { if let Ok ( entry ) = entry { // If it is a file with that same _filename_ (not full path) if entry . path ( ) . is_file ( ) && entry . file_name ( ) == target { return Ok ( Some ( entry . path ( ) . into ( ) ) ) ; } else if entry . path ( ) . is_dir ( ) { // I think if there are any dirs on that directory we have to // recursively search on them if let Some ( result ) = find_entry_in_dir ( & entry . path ( ) , target ) ? { return Ok ( Some ( result ) ) ; } } } } Ok ( None ) }
Returns the first entry on that directory whose filename is equal to target.
Returns the first entry on that directory whose filename is equal to target .
dir_path
&Path
target
&Path