如何监视Windows目录的更改? [英] How can I monitor a Windows directory for changes?

查看:128
本文介绍了如何监视Windows目录的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在Windows系统上的目录中进行更改时,我需要一个程序来立即通知更改。

When a change is made within a directory on a Windows system, I need a program to be notified immediately of the change.

有没有办法执行程序发生变化时

Is there some way of executing a program when a change occurs?

我不是C / C ++ / .NET程序员,所以如果我可以设置一些东西,以便更改可以触发批处理文件那么这将是理想的。

I'm not a C/C++/.NET programmer, so if I could set up something so that the change could trigger a batch file then that would be ideal.

推荐答案

使用 FileSystemWatcher ,如下所示,创建一个WatcherCreated Event()。我使用它来创建一个Windows服务,它观看一个网络文件夹,然后在新文件到达时发送一个指定的组。

Use a FileSystemWatcher like below to create a WatcherCreated Event(). I used this to create a Windows Service that watches a Network folder and then emails a specified group on arrival of new files.

// Declare a new FILESYSTEMWATCHER
protected FileSystemWatcher watcher;

string pathToFolder = @"YourDesired Path Here";

// Initialize the New FILESYSTEMWATCHER
Watcher = new FileSystemWatcher {Path = PathToFolder, IncludeSubdirectories = true, Filter = "*.*"};
Watcher.Created += new FileSystemEventHandler(WatcherCreated);
void WatcherCreated(object source , FileSystemEventArgs e)
{Code goes here for when a new file is detected}

这篇关于如何监视Windows目录的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆