// 리스트뷰에 폴더및 파일정보 삽입 private void ListViewSetting(String strPath) { InitImage(); GetSystemImgList sysimglst = new GetSystemImgList(); strPath = strPath + "\\"; DirectoryInfo directoryInfo = new DirectoryInfo(strPath); try { int count = directoryInfo.GetDirectories("*").Length + directoryInfo.GetFiles("*.*").Length; CallLoadingWnd(count); // 폴더 정보를 얻기 foreach (DirectoryInfo subdirectoryInfo in directoryInfo.GetDirectories("*")) { // 리스트뷰에 입력 imglstSmall.Images.Add(sysimglst.GetIcon(subdirectoryInfo.FullName, true, false)); imglstLarge.Images.Add(sysimglst.GetIcon(subdirectoryInfo.FullName, false, false)); count = imglstSmall.Images.Count; listView.Items.Add(subdirectoryInfo.Name, count - 1); listView.Items[count - 1].SubItems.Add(""); listView.Items[count - 1].SubItems.Add("파일 폴더"); listView.Items[count - 1].SubItems.Add(subdirectoryInfo.LastWriteTime.ToString()); listView.Items[count - 1].SubItems.Add(subdirectoryInfo.Attributes.ToString()); Application.DoEvents(); RepaintLoadingWnd(); } // 파일 정보(리스트뷰 입력) foreach (FileInfo fileInfo in directoryInfo.GetFiles("*.*")) { imglstSmall.Images.Add(sysimglst.GetIcon(fileInfo.FullName, true, false)); imglstLarge.Images.Add(sysimglst.GetIcon(fileInfo.FullName, false, false)); count = imglstSmall.Images.Count; listView.Items.Add(fileInfo.Name, count - 1); listView.Items[count - 1].SubItems.Add(fileInfo.Length.ToString()); listView.Items[count - 1].SubItems.Add((fileInfo.Extension.ToString()).Substring(1, 3)); listView.Items[count - 1].SubItems.Add(fileInfo.LastWriteTime.ToString()); listView.Items[count - 1].SubItems.Add(fileInfo.Attributes.ToString()); Application.DoEvents(); RepaintLoadingWnd(); } } catch { // 디렉토리/파일 정보 읽을때 예외 발생하면 무시(파일 속성때문에 예외 발생함) } CloseLoadingWnd(); }
// node에 하위 폴더 삽입 private void TreeNodeSetting(TreeNode node) { String strPath; int count; GetSystemImgList sysimglst = new GetSystemImgList(); strPath = node.FullPath + "\\"; DirectoryInfo directoryInfo = new DirectoryInfo(strPath); // 폴더 정보 try { // 폴더 정보를 얻기 foreach (DirectoryInfo subdirectoryInfo in directoryInfo.GetDirectories("*")) { count = node.Nodes.Add(new TreeNode(subdirectoryInfo.Name, imglstTree.Images.Count - 2, imglstTree.Images.Count - 1)); if (HasSubDirectory(node.Nodes[count].FullPath)) { node.Nodes[count].Nodes.Add("XXX"); } } } catch { CloseLoadingWnd(); // 디렉토리/파일 정보 읽을때 예외 발생하면 무시(파일 속성때문에 예외 발생함) } }
// 트리뷰에 드라이브 정보 입력 private void InitTreeDriveSetting() { String[] strDrives = null; String strTemp; GetSystemImgList sysimglst = new GetSystemImgList(); int count; strDrives = Directory.GetLogicalDrives(); imglstTree.Images.Clear(); foreach (string str in strDrives) { imglstTree.Images.Add(sysimglst.GetIcon(str, true, false)); count = treeView.Nodes.Add(new TreeNode(str.Substring(0, 2), imglstTree.Images.Count - 1, imglstTree.Images.Count - 1)); if (HasSubDirectory(str.Substring(0, 2))) { treeView.Nodes[count].Nodes.Add("XXX"); } } DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\"); foreach (DirectoryInfo subdirectoryInfo in directoryInfo.GetDirectories("*")) { imglstTree.Images.Add(sysimglst.GetIcon(subdirectoryInfo.FullName, true, false)); imglstTree.Images.Add(sysimglst.GetIcon(subdirectoryInfo.FullName, true, true)); } // 초기화면 C드라이브 선택 효과 treeView.SelectedNode = treeView.Nodes[1]; }