# Get most recent online file?

**URL:** https://discourse.processing.org/t/get-most-recent-online-file/22879
**Category:** Coding Questions
**Created:** [July 28, 2020, 5:53pm UTC](https://discourse.processing.org/t/get-most-recent-online-file/22879 "2020-07-28T17:53:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jetjaguar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jetjaguar/32/1370_2.png) [@jetjaguar](https://discourse.processing.org/u/jetjaguar)
#### Post date: [July 28, 2020, 5:53pm UTC](https://discourse.processing.org/t/get-most-recent-online-file/22879/1 "2020-07-28T17:53:22Z")

</div>

Imagine a public directory online, like this one: [https://neo.sci.gsfc.nasa.gov/archive/rgb/MOD\_LSTD\_E/](https://neo.sci.gsfc.nasa.gov/archive/rgb/MOD_LSTD_E/)

This directory has a file put into it usually every 8 days. I would like to get the newest file whenever the sketch is run. Now I could simply check for a file added today, and then go backwards a day at a time for 8 days until I find something, but that technique is quite slow.

Does anyone know of a way to examine the creation dates of files in such a directory so that I might be able to find the newest one?

Thank you in advance!

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [July 28, 2020, 6:48pm UTC](https://discourse.processing.org/t/get-most-recent-online-file/22879/2 "2020-07-28T18:48:20Z")

</div>

Load the page’s source code which is plain html, extract file names and modification dates and loaded them into a map or some sort of data container so you can sort it.

Kf

---

<div class="post-metadata">

### Author: ![jetjaguar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jetjaguar/32/1370_2.png) [@jetjaguar](https://discourse.processing.org/u/jetjaguar)
#### Post date: [July 28, 2020, 8:17pm UTC](https://discourse.processing.org/t/get-most-recent-online-file/22879/3 "2020-07-28T20:17:51Z")

</div>

That’s a good tip, thank you kfrajer.

I’m seeing if I can shortcut that by loading the html into a string, scraping the files names (that’s all I really need) and then only saving the last one it finds, since that is the newest.

---

<div class="post-metadata">

### Author: ![jetjaguar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jetjaguar/32/1370_2.png) [@jetjaguar](https://discourse.processing.org/u/jetjaguar)
#### Post date: [July 29, 2020, 3:20am UTC](https://discourse.processing.org/t/get-most-recent-online-file/22879/4 "2020-07-29T03:20:28Z")

</div>

OK I think I got it.

This chore is made a little easier by the fact that the files are listed in chronological order.

```auto
String[] ln = loadStrings("https://neo.sci.gsfc.nasa.gov/archive/rgb/MOD_LSTD_E/");
String page1 = "";
int ignore; // lines of code to ignore at the top of the webpage

for (int i=0;i<ln.length;i++) {
    //println(i+" "+ln[i]); //print html with line numbers
    page1 = page1+=ln[i];
}

String[][] test = matchAll(page1, ">MOD_LSTD_E_(.*?).PNG</a>");

//print ALL values found
//for (int i = 0; i < ln.length-ignore; i++) {
  //ignore = 12;
  // print(i + " "); println(test[i][1]);
//}

//print only last (most recent) value
ignore = 13;
print(test[int(ln.length-ignore)][1]);

```
