How to upload file in R when the name changes everyday

Viewed 29

I have a file that needs to be uploaded each day, file name MIS_01_10062022.xlsx. Each day MIS_01_ part of the file name is constant the date part - 10062022 changes due to date. How can I upload this file with out selecting it each day? Is it possible to select file by just mentioning the file name as MIS_01_*.

1 Answers

Here is a strategy of what you could try:

  • List all the in the directory that might be of interest, e.g. via a<-list.files(pattern="MIS_01_")
  • Save all file informations (e.g. when the files were created) in a second variable, e.g. via b<-file.info(a)
  • Find the latest file using the "mtime" column of this dataframe, e.g. via latest_file_index<-which.max(b$mtime) . This will return the index of the newest file, which you can again access in your initial variable a, via latest_file_name<-a[latest_file_index]
Related