I'm trying to write a maintenance routine to delete old files from an sd card when total file size is above a threshold.
I'm thinking about how to sort last-modified time and here is what I've come up with:
1. Use opendir and readdir() to read struct for each file in the folder.
2. With the file name, call stat() to get file size and last-modified time. Save name, size, last-mod in a list. Sum up the file sizes while enumerating files. If it exceeds the limit, proceed to maintenance after enumeration is done, otherwise quit.
Sort the list according to last-mod. Start deleting files from the sorted list of names and decrement total file size after each deletion, until the size falls below threshold.
I am wondering if there are any standard libraries to read sorted file names by last-modified and whether my above description is sound. Thanks.
Sort files by date and delete oldest files
Re: Sort files by date and delete oldest files
By the way, is there any "archive" attributes I can read/set in POSIX system? That would be great!
Re: Sort files by date and delete oldest files
A POSIX question and so not ESP32 specific (I am sure that ESP comply with POSIX). You will therefore probably get better help on StackOverflow etc because of user volumes. I would be suprised if there is not a posted solution to your question.
EDIT: Plus StackOverflow etc allow votes which simplifies your review.
EDIT: Plus StackOverflow etc allow votes which simplifies your review.
& I also believe that IDF CAN should be fixed.
Re: Sort files by date and delete oldest files
Thanks PeterR. I'll post on stack overflow and provide a link Ina reply if I can find an answer.
Re: Sort files by date and delete oldest files
PS Search first and show some attempt at solution with code else Stack will tend to roast you (or use a burner account!) But I think your's is a generic problem that (following an inteligent search) will have a well defined/accepted solution.
& I also believe that IDF CAN should be fixed.
Re: Sort files by date and delete oldest files
Thanks for you advice. I read a few hits from their auto-gen similar questions. My sense is that what I described was how it's done in all the posts I found (all different programming languages) but wonder if there's a better way.
Re: Sort files by date and delete oldest files
There are always better ways. Its great that you want to push forward. Delivery and improvement need to be held in balence though.
IMHO the modern agile approaches are to get 'working' (test/functional) and then you may reflect on better structure (refactor etc).
The solutions you read may not actually work well but you won't know that until you apply test cases. Empiric, test driven, then you learn IMHO.
IMHO the modern agile approaches are to get 'working' (test/functional) and then you may reflect on better structure (refactor etc).
The solutions you read may not actually work well but you won't know that until you apply test cases. Empiric, test driven, then you learn IMHO.
& I also believe that IDF CAN should be fixed.
Re: Sort files by date and delete oldest files
I agree. Trial and error. It seems that stackoverflow is overflowing with snobs anyway. Those who can't handle a single question without acting superior should just code and keep their mouths shut.PeterR wrote: ↑Fri Jan 17, 2020 1:10 amThere are always better ways. Its great that you want to push forward. Delivery and improvement need to be held in balence though.
IMHO the modern agile approaches are to get 'working' (test/functional) and then you may reflect on better structure (refactor etc).
The solutions you read may not actually work well but you won't know that until you apply test cases. Empiric, test driven, then you learn IMHO.
Who is online
Users browsing this forum: No registered users and 121 guests