İngilizce dilinde oku

Aracılığıyla paylaş


WatcherChangeTypes Sabit listesi

Tanım

Dosya veya dizinde oluşabilecek değişiklikler.

Bu sabit listesi, üyeleri için bit düzeyinde karşılaştırmayı destekler.

C#
[System.Flags]
public enum WatcherChangeTypes
Devralma
WatcherChangeTypes
Öznitelikler

Alanlar

Name Değer Description
All 15

Bir dosya veya klasörün oluşturulması, silinmesi, değiştirilmesi veya yeniden adlandırılması.

Changed 4

Dosya veya klasör değişikliği. Değişiklik türleri şunlardır: boyut, öznitelikler, güvenlik ayarları, son yazma ve son erişim zamanı değişiklikleri.

Created 1

Dosya veya klasör oluşturma.

Deleted 2

Bir dosya veya klasörün silinmesi.

Renamed 8

Bir dosya veya klasörün yeniden adlandırılması.

Örnekler

Aşağıdaki örnekte, disk sürücüsünde gerçekleşen dosya değişikliklerini (oluşturur, siler, yeniden adlandırır, değişiklikleri) izlemek için bir FileSystemWatcher'ın nasıl oluşturulacağı gösterilmektedir. Örnek ayrıca hata bildirimlerini düzgün bir şekilde nasıl alacağınızı da gösterir.

C#
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        //  Create a FileSystemWatcher to monitor all files on drive C.
        FileSystemWatcher fsw = new FileSystemWatcher("C:\\");

        //  Watch for changes in LastAccess and LastWrite times, and
        //  the renaming of files or directories.
        fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
            | NotifyFilters.FileName |NotifyFilters.DirectoryName;

        //  Register a handler that gets called when a
        //  file is created, changed, or deleted.
        fsw.Changed += new FileSystemEventHandler(OnChanged);

        fsw.Created += new FileSystemEventHandler(OnChanged);

        fsw.Deleted += new FileSystemEventHandler(OnChanged);

        //  Register a handler that gets called when a file is renamed.
        fsw.Renamed += new RenamedEventHandler(OnRenamed);

        //  Register a handler that gets called if the
        //  FileSystemWatcher needs to report an error.
        fsw.Error += new ErrorEventHandler(OnError);

        //  Begin watching.
        fsw.EnableRaisingEvents = true;

        Console.WriteLine("Press \'Enter\' to quit the sample.");
        Console.ReadLine();
    }

    //  This method is called when a file is created, changed, or deleted.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        //  Show that a file has been created, changed, or deleted.
        WatcherChangeTypes wct = e.ChangeType;
        Console.WriteLine("File {0} {1}", e.FullPath, wct.ToString());
    }

    //  This method is called when a file is renamed.
    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        //  Show that a file has been renamed.
        WatcherChangeTypes wct = e.ChangeType;
        Console.WriteLine("File {0} {2} to {1}", e.OldFullPath, e.FullPath, wct.ToString());
    }

    //  This method is called when the FileSystemWatcher detects an error.
    private static void OnError(object source, ErrorEventArgs e)
    {
        //  Show that an error has been detected.
        Console.WriteLine("The FileSystemWatcher has detected an error");
        //  Give more information if the error is due to an internal buffer overflow.
        if (e.GetException().GetType() == typeof(InternalBufferOverflowException))
        {
            //  This can happen if Windows is reporting many file system events quickly
            //  and internal buffer of the  FileSystemWatcher is not large enough to handle this
            //  rate of events. The InternalBufferOverflowException error informs the application
            //  that some of the file system events are being lost.
            Console.WriteLine(("The file system watcher experienced an internal buffer overflow: " + e.GetException().Message));
        }
    }
}

Açıklamalar

Her WatcherChangeTypes üye içindeki FileSystemWatcherbir olayla ilişkilendirilir. Olaylar hakkında daha fazla bilgi için bkz Created. , Deleted, Changedve Renamed.

Şunlara uygulanır

Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Ayrıca bkz.