我需要监视一个文件夹,查看是否已上传一个或多个文件。然后我需要获取已上传的最新文件的创建日期和时间,并查看文件的创建时间是否距离当前时间超过 30 分钟。我已经使用 FileSystemWatcher 来监视文件夹,但是我应该如何继续查找最新文件并将其与当前时间进行比较。
private void watch()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.NotifyFilter = NotifyFilters.LastWrite;
NotifyFilters.DirectoryName;
watcher.Filter = "*.*";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
Private void OnChanged(object source, FileSystemEventArgs e)
{
//Copies file to another directory.
}
我该如何在 c# 中做到这一点。请帮忙!