FileSystemWatcher 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
FileSystemWatcher 클래스의 새 인스턴스를 초기화합니다.
오버로드
| Name | Description |
|---|---|
| FileSystemWatcher() |
FileSystemWatcher 클래스의 새 인스턴스를 초기화합니다. |
| FileSystemWatcher(String) |
모니터링할 지정된 디렉터리가 지정된 경우 클래스의 FileSystemWatcher 새 인스턴스를 초기화합니다. |
| FileSystemWatcher(String, String) |
모니터링할 지정된 디렉터리 및 파일 형식이 FileSystemWatcher 지정된 경우 클래스의 새 인스턴스를 초기화합니다. |
FileSystemWatcher()
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
FileSystemWatcher 클래스의 새 인스턴스를 초기화합니다.
public:
FileSystemWatcher();
public FileSystemWatcher();
Public Sub New ()
예제
다음 예제에서는 런타임에 FileSystemWatcher 지정된 디렉터리를 감시하는 개체를 만듭니다. 개체는 FileSystemWatcher 디렉터리에서 LastWrite 텍스트 파일의 생성, 삭제 또는 이름 변경을 감시합니다 LastAccess . 파일이 변경, 생성 또는 삭제되면 파일 경로가 콘솔에 표시됩니다. 파일 이름을 바꾸면 이전 경로와 새 경로가 콘솔에 표시됩니다.
이 예제에서는 네임스페이 System.Diagnostics 스 및 System.IO 네임스페이스를 사용합니다.
using System;
using System.IO;
namespace MyNamespace
{
class MyClassCS
{
static void Main()
{
using var watcher = new FileSystemWatcher(@"C:\path\to\folder");
watcher.NotifyFilter = NotifyFilters.Attributes
| NotifyFilters.CreationTime
| NotifyFilters.DirectoryName
| NotifyFilters.FileName
| NotifyFilters.LastAccess
| NotifyFilters.LastWrite
| NotifyFilters.Security
| NotifyFilters.Size;
watcher.Changed += OnChanged;
watcher.Created += OnCreated;
watcher.Deleted += OnDeleted;
watcher.Renamed += OnRenamed;
watcher.Error += OnError;
watcher.Filter = "*.txt";
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
{
return;
}
Console.WriteLine($"Changed: {e.FullPath}");
}
private static void OnCreated(object sender, FileSystemEventArgs e)
{
string value = $"Created: {e.FullPath}";
Console.WriteLine(value);
}
private static void OnDeleted(object sender, FileSystemEventArgs e) =>
Console.WriteLine($"Deleted: {e.FullPath}");
private static void OnRenamed(object sender, RenamedEventArgs e)
{
Console.WriteLine($"Renamed:");
Console.WriteLine($" Old: {e.OldFullPath}");
Console.WriteLine($" New: {e.FullPath}");
}
private static void OnError(object sender, ErrorEventArgs e) =>
PrintException(e.GetException());
private static void PrintException(Exception? ex)
{
if (ex != null)
{
Console.WriteLine($"Message: {ex.Message}");
Console.WriteLine("Stacktrace:");
Console.WriteLine(ex.StackTrace);
Console.WriteLine();
PrintException(ex.InnerException);
}
}
}
}
Imports System.IO
Namespace MyNamespace
Class MyClassVB
Shared Sub Main()
Using watcher = New FileSystemWatcher("C:\path\to\folder")
watcher.NotifyFilter = NotifyFilters.Attributes Or
NotifyFilters.CreationTime Or
NotifyFilters.DirectoryName Or
NotifyFilters.FileName Or
NotifyFilters.LastAccess Or
NotifyFilters.LastWrite Or
NotifyFilters.Security Or
NotifyFilters.Size
AddHandler watcher.Changed, AddressOf OnChanged
AddHandler watcher.Created, AddressOf OnCreated
AddHandler watcher.Deleted, AddressOf OnDeleted
AddHandler watcher.Renamed, AddressOf OnRenamed
AddHandler watcher.Error, AddressOf OnError
watcher.Filter = "*.txt"
watcher.IncludeSubdirectories = True
watcher.EnableRaisingEvents = True
Console.WriteLine("Press enter to exit.")
Console.ReadLine()
End Using
End Sub
Private Shared Sub OnChanged(sender As Object, e As FileSystemEventArgs)
If e.ChangeType <> WatcherChangeTypes.Changed Then
Return
End If
Console.WriteLine($"Changed: {e.FullPath}")
End Sub
Private Shared Sub OnCreated(sender As Object, e As FileSystemEventArgs)
Dim value As String = $"Created: {e.FullPath}"
Console.WriteLine(value)
End Sub
Private Shared Sub OnDeleted(sender As Object, e As FileSystemEventArgs)
Console.WriteLine($"Deleted: {e.FullPath}")
End Sub
Private Shared Sub OnRenamed(sender As Object, e As RenamedEventArgs)
Console.WriteLine($"Renamed:")
Console.WriteLine($" Old: {e.OldFullPath}")
Console.WriteLine($" New: {e.FullPath}")
End Sub
Private Shared Sub OnError(sender As Object, e As ErrorEventArgs)
PrintException(e.GetException())
End Sub
Private Shared Sub PrintException(ex As Exception)
If ex IsNot Nothing Then
Console.WriteLine($"Message: {ex.Message}")
Console.WriteLine("Stacktrace:")
Console.WriteLine(ex.StackTrace)
Console.WriteLine()
PrintException(ex.InnerException)
End If
End Sub
End Class
End Namespace
설명
Windows NT 또는 Windows 2000이 없는 원격 컴퓨터는 볼 수 없습니다. Windows NT 4.0 컴퓨터에서 원격 Windows NT 4.0 컴퓨터를 볼 수 없습니다.
다음 표에서는 인스턴스에 대한 초기 속성 값을 보여 줍니다 FileSystemWatcher.
| 재산 | 초기 값 |
|---|---|
| NotifyFilter | bitwise OR 조합 , LastWriteFileName및DirectoryName |
| EnableRaisingEvents | false |
| Filter | "*.*"(모든 파일 보기) |
| IncludeSubdirectories | false |
| InternalBufferSize | 8192 |
| Path | 빈 문자열("") |
메모
구성 요소는 설정 EnableRaisingEventstrue될 때까지 Path 지정된 디렉터리를 감시하지 않습니다.
추가 정보
- NotifyFilters
- FileSystemEventArgs
- FileSystemEventHandler
- InternalBufferOverflowException
- Path
- RenamedEventArgs
- RenamedEventHandler
- WaitForChangedResult
- WatcherChangeTypes
적용 대상
FileSystemWatcher(String)
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
모니터링할 지정된 디렉터리가 지정된 경우 클래스의 FileSystemWatcher 새 인스턴스를 초기화합니다.
public:
FileSystemWatcher(System::String ^ path);
public FileSystemWatcher(string path);
new System.IO.FileSystemWatcher : string -> System.IO.FileSystemWatcher
Public Sub New (path As String)
매개 변수
- path
- String
표준 또는 UNC(유니버설 명명 규칙) 표기법으로 모니터링할 디렉터리입니다.
예외
매개 변수는 path .입니다 null.
path 가 너무 깁니다.
설명
메모
구성 요소는 설정 EnableRaisingEventstrue될 때까지 Path 지정된 디렉터리를 감시하지 않습니다.
구성 요소는 개인 컴퓨터, 네트워크 드라이브 또는 원격 컴퓨터의 파일을 볼 수 있습니다.
Windows NT 또는 Windows 2000이 없는 원격 컴퓨터는 볼 수 없습니다. Windows NT 4.0 컴퓨터에서 원격 Windows NT 4.0 컴퓨터를 볼 수 없습니다. 속성은 Filter 기본적으로 모든 파일을 감시하도록 설정됩니다.
추가 정보
- NotifyFilters
- FileSystemEventArgs
- FileSystemEventHandler
- Filter
- InternalBufferOverflowException
- Path
- RenamedEventArgs
- RenamedEventHandler
- WaitForChangedResult
- WatcherChangeTypes
적용 대상
FileSystemWatcher(String, String)
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
- Source:
- FileSystemWatcher.cs
모니터링할 지정된 디렉터리 및 파일 형식이 FileSystemWatcher 지정된 경우 클래스의 새 인스턴스를 초기화합니다.
public:
FileSystemWatcher(System::String ^ path, System::String ^ filter);
public FileSystemWatcher(string path, string filter);
new System.IO.FileSystemWatcher : string * string -> System.IO.FileSystemWatcher
Public Sub New (path As String, filter As String)
매개 변수
- path
- String
표준 또는 UNC(유니버설 명명 규칙) 표기법으로 모니터링할 디렉터리입니다.
- filter
- String
감시할 파일의 형식입니다. 예를 들어 "*.txt"는 모든 텍스트 파일의 변경 내용을 감시합니다.
예외
path 가 너무 깁니다.
설명
메모
구성 요소는 설정 EnableRaisingEventstrue될 때까지 Path 지정된 디렉터리를 감시하지 않습니다.
구성 요소는 개인 컴퓨터, 네트워크 드라이브 또는 원격 컴퓨터의 파일을 볼 수 있습니다.
Windows NT 또는 Windows 2000이 없는 원격 컴퓨터는 볼 수 없습니다. Windows NT 4.0 컴퓨터에서 원격 Windows NT 4.0 컴퓨터를 볼 수 없습니다.
추가 정보
- NotifyFilters
- FileSystemEventArgs
- FileSystemEventHandler
- Filter
- InternalBufferOverflowException
- Path
- RenamedEventArgs
- RenamedEventHandler
- WaitForChangedResult
- WatcherChangeTypes