Jump to content

Find file from folder with latest date modified stamp


john_doemoor

Recommended Posts

It would be some pretty easy code to write. Do you have any experience with PHP? If not, then you should post in the freelance forum. If you do have some experience, give it a try then post back with any specific problems you have.

 

Here is the process I would follow:

 

1. Create two variable to hold 1. the file namepath with the newest date and 2) the file's date. Set the first to false and the latter to 0.

 

2. Use glob() to get all the csv files from the specific directory into an array.

 

3. Loop through all files (using foreach) returned by glob.

 

4. Use filemtime() to get the last modified date of the file.

 

5. Test if that value is greater than the variable that holds the date of the recent file (created in step 1). If so, then set the two variables to the current file and date respectively.

 

When the loop ends you will either have the most recent file and time in those two variables or (if there were no csv files) the file variable will be false.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.