본문 바로가기
C#/파일 및 디렉토리

Windows 탐색기 만들기 II

by edupicker(체르니) 2010. 5. 27.
음 얼마 전 올린 C#으로 윈도우 탐색기와 유사한 프로그램을 만드는 글에 대해서 몇몇 분이 소스를 공개하거나 보내 줄 수 없느냐는 요청을 하셔서 그 중 핵심이 되는 부분들에 대한 간략한 코드를 올려봅니다.

컴퓨터에 존재하는 드라이브 정보를  파악하려면 GetDrives() 메서드를 다음과 같이 이용합니다. 
DriveInfo[] allDrives = DriveInfo.GetDrives();

트리노드에 디렉토리 정보 채우기
DirectoryInfo dir = new DirectoryInfo(dirNode.FullPath);
foreach (DirectoryInfo dirItem in dir.GetDirectories())
{
  TreeNode newNode = new TreeNode(dirItem.Name);
  newNode.ImageIndex = 2;
  newNode.SelectedImageIndex = 2;
  dirNode.Nodes.Add(newNode);
  newNode.Nodes.Add("*");
}

트리 노드가 확장되기 전에 발생하는 이벤트 : TreeView의 BeforeExpand
트리 노드를 클릭하면 발생하는 이벤트 : NodeMouseClick

하부 디렉토리를 파악은 DirecotryInfo 클래스의 GetDirectories() 메서드를 이용
foreach (DirectoryInfo dirItem in dir.GetDirectories())

디렉토리에 존재하는 파일들을 파악하기 위해서 GetFiles() 메서드를 이용
FileInfo[] fishow = dir.GetFiles();
foreach (FileInfo fri in fishow)

위와 같은 부분들을 이용하여 앞서 "C#으로 윈도우 탐색기 만들기" 프로그램을 만들었습니다.
윈도우 탐색기를 만드는 분들에게 이 글이 조금이나마 보탬이 되기를 바라며 이만 줄입니다.

'C# > 파일 및 디렉토리' 카테고리의 다른 글

윈도우 탐색기 만들기(풀소스)  (17) 2011.04.05
FileSystem Data Handling II  (0) 2009.04.23
FileSystem Data Handling III  (0) 2009.04.23
FileSystem Data Handling I  (0) 2009.04.22