初學編程的在這裏....希望這是有道理的:)FileSystemWatcher的 - 同步更改的文件
我創建了一個控制檯應用程序,我需要在後臺運行,並觀看目錄的更改/重命名事件。我已經使用了FileWatcher類,並增加了事件處理程序像這樣:
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
和定義的處理程序然後在下面像這樣:
private static void OnChanged(object source, FileSystemEventArgs e)
{
//specify what is done when a file is changed, created or deleted
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
private static void OnRenamed(object source, RenamedEventArgs e)
{
//specify what is done when a file is renamed
Console.WriteLine("File {0} renamed to {1}", e.OldFullPath, e.FullPath);
我希望能夠在一些代碼添加將任何已更改/重命名的文件轉儲到另一個本地目錄,但我不知道從哪裏開始。在一分鐘的控制檯回寫FULLPATH給我,但我非常希望它複製到另一個文件夾
謝謝你們