I often create log/report files using various shell scripts. This is fine, but most of the time I only need to look at the contents briefly - usually the same day or up to a week later.
What I'd like to do is to be able to flag the file as expiring so after a given period of time, the file is either deleted or moved to an archive directory.
As I have control over the file creation, I could of course give it a certain extension e.g. .SEF and write a service to parse the directories on my hard drive periodically, but this seems a bit clunky.
I've also looked into custom file attributes:
http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/173ab6de-3cd8-448f-8c42-de9d2240b913
But I'd need to write something to add the file attribute to the file. So in Powershell/SFU or similar:
cat JobOutput.txt | grep -e Error | expire > report.txt
Or plain old windows:
type JobOutput.txt | findstr Error | expire > report.txt
Has anyone done anything remotely like this?
Edit:
What I've described above is just one facet of what I'd like to do. For example, you might want to send an email which requires a response within a time limit and then gets deleted after that time.
Another example might be a document you release with details of a temporary system workaround which you don't want used after a given amount of time.
We're into the vagaries of various applications now of course, but the idea of custom file attributes looked promising and appealing. The problem of course would be how they'd be applied to each of the file types...
For now, I'm happy to close this based on the question as I originally posed it, in which case, I could define a custom extension which gets cleared up by a scheduled job.
Solution:
OK, I decided to go with the Powershell solution (with a slight tweak) since I'm pretty familiar with that:
$HowManyDays = 15
$LastWrite = (Get-Date).AddDays(-$HowManyDays)
Get-ChildItem -recurse -include *.sef |
Where {$_.LastWriteTime -le "$LastWrite"} |
Remove-Item
Many thanks for your help on this.