Jump to content

Recommended Posts

I have a problem,

I would have to find a .csv file that is the most latest modified from a specific directory.

And return the name of the latest modified file.

Does some1 have a working example for this kind of case?

 

Thank you in advance!

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.

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.