FileSystemWatcher는 특정 디렉토리에서의 파일의 생성, 수정, 삭제, 이름변경 시 모니터링 할 경우 사용 할 수 있는 클래스입니다.
private void Form1_Load(object sender, EventArgs e)
{
fileSystemWatcher1.Filter = "*.txt";//모니터링 할 파일의 확장자 정의. 기본은 *.* 모든 확장자입니다.
fileSystemWatcher1.Path = "C:\\";//모니터링 할 디렉토리 지정
}
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{
MessageBox.Show("CHANGED :" + e.FullPath);//텍스트 파일의 내용이 변경 됐을 경우
}
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
MessageBox.Show("CREATED : " + e.FullPath);//텍스트 파일 생성 시
}
private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show("DELETE : " + e.FullPath);//텍스트 파일 삭제 시
}
private void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
{
MessageBox.Show("RENAME : " + e.OldFullPath + "\n" + e.FullPath);//텍스트 파일 이름 변경 됐을 경우 발생
}
'C#' 카테고리의 다른 글
[C#]이미지 그리기 예제 (0) | 2016.04.05 |
---|---|
[C#]이미지 회전 예제 (0) | 2016.04.05 |
MSSQL Paging Query (0) | 2016.03.30 |
[C#]실행 프로그램 경로 얻기 예제 (0) | 2016.03.29 |
Oracle paging Query (0) | 2016.03.29 |