我想给当系统监控已discoverd与“.TXT”,“ .DOC”或“的.docx”结束了创建的文件已被发现的文件。我的问题是系统监视器只发现以“ .txt”结尾的文件。FileSystemWatcher的:多个类型
这里是我的代码:
private String Attachmenttosend
{
get { return attachmentfile; }
set { attachmentfile = value; }
}
private void NewFileSystemWatcher()
{
String filter = "*.txt,*.doc,*.docx";
string[] FileExtension = filter.Split(',');
for (int i = 0; i < FileExtension.GetLength(0); i++)
{
watcher = new FileSystemWatcher(folder); // on its own Thread
watcher.Created += new FileSystemEventHandler(NewEMail);
attachmenttosend.Add(Attachmenttosend);
watcher.Filter = FileExtension[i];
watcher.EnableRaisingEvents = true;
watchlist.Add(watcher);
}
Send(Attachmenttosend);
}
private void NewEMail(Object source, FileSystemEventArgs e)
{
while (Locked(e.FullPath)) // check if the file is used
{
Thread.Sleep(10);
}
Attachmenttosend = e.FullPath; // store the filename
}
可能的重复http://stackoverflow.com/questions/6965184/how-to-set-filter-for-filesystemwatcher-for-multiple-file-types –
你想捕捉特定任何文件的每一个修改目录? – terrybozzio
如果创建了一个文件(或更多)(endig用.txt,.doc或.docx),那么systemwatcher应该发现那个/这些文件并给我返回文件的名称。它仅适用于* .txt。像在链接http://stackoverflow.com/questions/6965184/how-to-set-filter-for-filesystemwatcher-for-multiple-file-types我为每个文件扩展名创建一个FileSystemWatcher对象。 – funk