使用FileSystemWatcher的在C#中的单个文件 [英] Use FileSystemWatcher on a single file in C#

查看:159
本文介绍了使用FileSystemWatcher的在C#中的单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试设置监视器路径,像这样一个文件:

When i try to set the watcher path to a single file like so:

watcher.Path = filePath1;

我得到的错误:

I get the error:

The directory name C:\Cromos 3.0\repository\diagnostics\dwm01_2011_06_13__09_03.LXD is invalid.

你能只设置的文件夹路径的目录?

Can you only set the path to a folder directory?

推荐答案

您错误设置路径属性有一个完整的文件名

Your error is setting the Path property with a full filename

watcher.Path = Path.GetDirectoryName(filePath1); 
watcher.Filter = Path.GetFileName(filePath1);

应该工作。

这篇关于使用FileSystemWatcher的在C#中的单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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