How can I Delete Oldest File in FTP Server?

I’m Choi. Nice to See you.

I am using the X20CP0484 CPU. Currently, I am using the DirInfo function to check the number of log data files created in the PLC. When the number exceeds a certain limit, I use the DirRead function to retrieve the filenames and then use the FileDelete function to delete the corresponding files. However, sometimes the DirRead function returns the most recent file instead of the oldest file. Is there any way to ensure that the oldest file is returned?

Here is Some Code


image

hello Choi Haechang:

From what I see, the DirRead also returns in the “pData” the date of last modification, which I believe you can use it to determine whether the directory you have selected is oldest or not (with a loop).

For more information: here

2 Likes

Hi,

like Wenbo already answered right, you have to read all files information of the whole directory to identify the oldest file.
For perfomance reasons, you should use DirReadEx() instead of DirRead().

Best regards!

2 Likes