使用FileSystemWatcher对象.这是一些代码来做你想要的.
// Declares the FileSystemWatcher object
FileSystemWatcher watcher = new FileSystemWatcher();
// We have to specify the path which has to monitor
watcher.Path = @"\\somefilepath";
// This property specifies which are the events to be monitored
watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite | NotifyFilters.FileName | notifyFilters.DirectoryName;
watcher.Filter = "*.*"; // Only watch text files.
// Add event handlers for specific change events...
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
// Begin watching.
watcher.EnableRaisingEvents = true;
// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
}
嗯...有趣的问题。首先,我会向您指出FileSystemWatcher类。但是,如果您想让它根据用户请求工作,那么您似乎可能需要最初存储目录信息,然后在每次用户请求时进行比较。我可能会选择 FileSystemWatcher 并存储结果。
| 归档时间: |
|
| 查看次数: |
3448 次 |
| 最近记录: |