Introduction
Get Information about when files were last updated in a directory.
Background
I was developing an ASP application where we worked on a TEST server first and then copied the files that contained the updated files to the LIVE server, I found myself forgetting on what files i had updated, so i decided to build an easy console app to show me what files that had been updated.
Using the code
static string path = @"Z:\";
static void Main(string[] args)
{
if (!Directory.Exists(path))
{
Console.WriteLine("The Directory doesnt exist, or it cant be accessed!");
Console.ReadLine();
}
else
{
List<string> fl = Getfiles(path);
foreach (string f in fl)
{
StreamWriter sw;
sw = File.AppendText(@"T:\Desktop\test.txt");
sw.WriteLine(f);
sw.Close();
Console.WriteLine(f);
}
}
Console.ReadLine();
}
public static List<string> Getfiles(string path)
{
List<string> fileList = new List<string>();
string[] subDirectories = Directory.GetDirectories(path);
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
DateTime dt = File.GetLastWriteTime(file);
if (dt.ToShortDateString() == DateTime.Today.ToShortDateString())
{
fileList.Add(file + " " + dt);
}
}
foreach (string di in subDirectories)
{
string[] fi = Directory.GetFiles(di);
foreach (string f in fi)
{
DateTime dt = File.GetLastWriteTime(f);
if (dt.ToShortDateString() == DateTime.Today.ToShortDateString())
{
fileList.Add(f +" "+ dt);
}
}
}
return fileList;
}
Points of Interest
This is my first article, so please be gentle :)
Im sure theres alot of things you can do better than I have done. Feel free to comment on things that can be improved.
History
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.