while ((dir = readdir(d)) != NULL) { regmatch_t pmatch[2]; // To store the matched timestamp if (regexec(®ex, dir->d_name, 2, pmatch, 0) == 0) { // Extract the timestamp from the filename char timestamp_str[256]; int len = pmatch[1].rm_eo - pmatch[1].rm_so; strncpy(timestamp_str, dir->d_name + pmatch[1].rm_so, len); timestamp_str[len] = '\0';
// Convert timestamp to time_t
time_t timestamp = atol(timestamp_str);
// Check if this is the most recent file
if (timestamp > most_recent_time) {
most_recent_time = timestamp;
strncpy(most_recent_file, dir->d_name, sizeof(most_recent_file) - 1);
most_recent_file[sizeof(most_recent_file) - 1] = '\0';
file_found = true;
}