有隻有一個ComboBox生成一個表單:enter image description here使用filewatcher將文件發送到特定的文件夾
而且在驅動器d一個MyTest
文件夾,你可以找到Folder1
,Folder2
,Folder3
enter image description here
我想看的任何如果在組合框中選擇Folder1
,則將.txt
文件添加到文件夾MyTest
中,並將它們移動到Folder1
aso
public void CreateFileWatcher(string path)
{
FileSystemWatcher fsw = new FileSystemWatcher("D:\\MyTest");
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
fsw.Changed += new FileSystemEventHandler(OnChanged);
fsw.Created += new FileSystemEventHandler(OnChanged);
fsw.Deleted += new FileSystemEventHandler(OnChanged);
fsw.Error += new ErrorEventHandler(OnError);
fsw.EnableRaisingEvents = true;
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
}
private static void OnError(object source, ErrorEventArgs e)
{
Console.WriteLine("The FileSystemWatcher has detected an error");
if (e.GetException().GetType() == typeof(InternalBufferOverflowException))
{
Console.WriteLine(("The file system watcher experienced an internal buffer overflow: " + e.GetException().Message));
}
}
它可以工作,那麼你會遇到一個問題? –
我不知道該怎麼做。我應該在某些地方使用'File.Move'和'comboBox1.SelectedIndex'嗎? – Rossalinda
提示:檢查FileSystemEventArgs的屬性 – jeroenh