我想給當系統監控已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