Get the latests File Created

I have a directory that is going to have files created in it once a day, I want to make sure my application can grab the latest file added to that folder

I have

Dim files As String()

Dim theFiles As String = Directory.GetFiles("C:\SomeDirectory")

theFiles = files(0)

but all this does is get the first file at the top of list in the directory...so if a newer one is added under it...It s till is grabing the one at the zero positon....any help with this




Answer this question

Get the latests File Created

  • honeysip

    GetFiles doesn't sort the files first, so you can't rely on the index to give you a specific file. Try this working example:
  • Get the latests File Created