I have few files in a directory(C:\MY_FOLDER\Freeze). Lets say i have two file with datetime infront of that. As shown below :
I have to read the most recent file in R. Help me please. I tried searching for the answers, but everywhere its in regarding with Linux system. "ctime" & "mtime" not working here.
File Explorer has a convenient way to search recently modified files built right into the “Search” tab on the Ribbon. Switch to the “Search” tab, click the “Date Modified” button, and then select a range. If you don't see the “Search” tab, click once in the search box and it should appear.
List files, displaying the most recently created or changed files first, by using the ls -t command.
We can use file.info
with list.files
. list.files
would list all the files in the interested directory and file.info
would give the details of all those files. We then get most recently modified file using which.max
on mtime
and then get the corresponding path of that file.
df <- file.info(list.files("/path/to/your/directory", full.names = T))
rownames(df)[which.max(df$mtime)]
#[1] "/path/to/your/directory/Interested_file.xlsx"
You can then use any of the commands to read csv or excel from that path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With