storing text in a text file for a specified length of time.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
storing text in a text file for a specified length of time.
Is there anyway to store text in a text file for a specified length of time? For instance, writing something to a text file and the erasing it two weeks after it was entered.
I have figured out how to add dates but I still dont know how to compare them.
I want to compare the dates that they were entered into thew text file with the date of the prsent day. If they have been in the text file for more than a week I want to delete them.
I assume you are using VB .Net for this since you were for your other questions, so here's a quick description of what you could do.
Read in the whole file into an ArrayList, reading it in one line at a time and adding each line as an element of the array.
After the file is read into the array, go through each element of the array. For each line extract the date part. (How you do this depends heavily on the format of the date you use and the way the rest of the line looks, if you are using comma-delimited fields for example, a simple string.split should suffice.)
Convert the date string to a DateTime object using the DateTime.Parse method.
Compare the newly created DateTime object with a DateTime object representing the oldest entry you want to keep.
If the date you read in is older than the dates you want to keep, remove that line from the array list
Continue the last few steps above until you've compared all entries in the file
When done, re-write your file to disk with only the remaining entries in your ArrayList
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.