Are you using Synopsis for Static Code Analysis? Can you set it such that the moment the scan finishes, it generates a report? With that you have your mtime. Use your mtime as your date for the file. That is the best I can help you. I do not know your use case. If you had something to show how you want it to look, that would help. I have changed the code to create a column for date using mtime. Good luck
library(data.table)
library(lubridate)
#Function to generate datatable using newest csv
read_newest_file <- function(dir_with_files, pattern){
df <- data.table(file.info(dir(dir_with_files, pattern = pattern, full.names = T)),
keep.rownames=TRUE)
setnames(df, "rn", "filename")
df[, create_date:= paste(months(mtime), year(mtime), sep = " ")]
return(df[,c(1,12, 5:7)])
}
dir_with_files <- "./results" # Directory with files
current_files <- read_newest_file(dir_with_files, "^cve" )
print(current_files)
> print(current_files)
filename create_date mtime ctime atime
1: ./results/cve_affected_products.csv June 2019 2019-06-17 00:02:45 2019-06-17 00:02:45 2019-05-27 05:39:57
2: ./results/cve_cpes.csv June 2019 2019-06-17 00:02:45 2019-06-17 00:02:45 2019-05-27 05:39:57
3: ./results/cve_cvss_scores.csv June 2019 2019-06-17 00:02:45 2019-06-17 00:02:45 2019-05-27 05:39:57
4: ./results/cve_reference_urls.csv June 2019 2019-06-17 00:02:45 2019-06-17 00:02:45 2019-05-27 05:39:57
5: ./results/cve_related_problems.csv June 2019 2019-06-17 00:02:45 2019-06-17 00:02:45 2019-05-27 05:39:57
>
They you can clean filename column to only reflect name.