At program startup, use Directory.GetFiles(path) to get the list of files.
Then create a timer, and in its elapsed event call hasNewFiles:
static List<string> hasNewFiles(string path, List<string> lastKnownFiles)
{
List<string> files = Directory.GetFiles(path).ToList();
List<string> newFiles = new List<string>();
foreach (string s in files)
{
if (!lastKnownFiles.Contains(s))
newFiles.Add(s);
}
return new List<string>();
}
In the calling code, you'll have new files if:
List<string> newFiles = hasNewFiles(path, lastKnownFiles);
if (newFiles.Count > 0)
{
processFiles(newFiles);
lastKnownFiles = newFiles;
}
edit: if you want a more linqy solution:
static IEnumerable<string> hasNewFiles(string path, List<string> lastKnownFiles)
{
return from f in Directory.GetFiles(path)
where !lastKnownFiles.Contains(f)
select f;
}
List<string> newFiles = hasNewFiles(path, lastKnownFiles);
if (newFiles.Count() > 0)
{
processFiles(newFiles);
lastKnownFiles = newFiles;
}