Reputation: 2297
I have those folders with names of dates under "c:/Document/"
I wonder whether there is a way that I can auto read the most recent date folder in?
Such as get the latest folder names and datadate<-XXX
, and then my input can auto point to the most recent folder by input_dir <-Paste0("c:/Document/", datadate, "/")
In my example, it will be 20210823
for the datadate
.
any suggestions or better way to achieve this goal?
Upvotes: 2
Views: 556
Reputation: 887501
We may use file.info
to find the most recent ones opened with ctime
etc
input_dir[which.max(file.info(input_dir)$ctime)]
Upvotes: 2
Reputation: 8811
You can use the function list.files(path = path,pattern = pattern)
to get the name of your folders,
where tou can define a path and pattern for the name of your folders. After that you could:
folders <- c("20210603","20210625","20210823")
max_date_folder <-
folders %>%
sort() %>%
tail(1)
path <- "C:/Documents"
input_dir <- file.path(path,max_date_folder)
input_dir
[1] "C:/Documents/20210823"
Upvotes: 3