Console App that scans for changes in a directory past 24 hours
I'm creating a program that scans for changes, not create or delete, in
ALL the files in a given directory, and all of his sub directories, in the
past 24 hours. I've seen lots of other examples/tutorials but not all of
them do what I'm looking for.
This is my code so far:
using System.IO;
public static void Main(string[] args)
{
string myDirectory =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
@"C:\Path");
var directory = new DirectoryInfo(myDirectory);
DateTime from_date = DateTime.Now.AddDays(-1);
DateTime to_date = DateTime.Now;
var files = directory.GetFiles().Where(file =>
file.LastWriteTime >= from_date && file.LastWriteTime <=
to_date).ToArray();
Console.WriteLine();
}
The problem is that the code above only tells me the last change in the
directory. What I want is a log of all the changes in the directory.
I am a learning student, so lots of explanation would be great! :)
I am NOT, I repeat NOT, looking for FileSystemWatcher, I don't want my
server to stay on for 24 hours straight. I want to start this program once
every 24 hours, make a log, close it. If anyone can help me out with this,
or at least give me something to start with, I would very much appreciate
it!
No comments:
Post a Comment