Skip to content
Tags

File cleanup

by on August 15, 2012

So you’re generating log files with all the output from your tests, showing passes and failures.

However, now everything is just building up and you’re ending up with tons of log files. It’s tedious to delete them all except the ones you want. So I wrote a little function that cleans up all but the current days log files.

public void deleteArchivedLogs()
{
string LogArchive = @"path\to\log\archive\folder";
//I used my resources to store a path and just accessed it using myRes.LogArchive
//But for this example, i changed it to use a string we set in this function
var files = new DirectoryInfo(LogArchive).GetFiles("*.*");
foreach (var file in files)
{
if (file.LastWriteTime < DateTime.Today) //if the file's modify date is older than today, delete the file
{
File.Delete(file.FullName);
}
}
}

From → C#, Code Snippets

Leave a Comment

Leave a comment

NE1 Atoll

The Official blog of NE1 Games

Selenium for .Net using C# language

Adventures in Coding, gaming and other fun things in my life

Coded UI 101 - Understanding Coded UI Tests

Adventures in Coding, gaming and other fun things in my life