// завантаження дерева каталогів void Ctvi_Expanded(object sender, RoutedEventArgs e) { MyTreeViewItem tvi = (MyTreeViewItem)sender; foreach (MyTreeViewItem ctvi in tvi.Items) { if (ctvi.Type == "DirectoryInfo") { DirectoryInfo dir = new DirectoryInfo(ctvi.Path); foreach (DirectoryInfo cdir in dir.GetDirectories()) { MyTreeViewItem ctvi1 = new MyTreeViewItem(); ctvi1.Expanded += new RoutedEventHandler(Ctvi_Expanded); ctvi1.Header = cdir.Name; ctvi1.Path = cdir.FullName; ctvi1.Type = cdir.GetType().Name; if (ctvi.Items.Contains(ctvi1.Header) == false) { ctvi.Items.Add(ctvi1); } } } } e.Handled = true; }
// Вибір дисків private void cmbDrive_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.tvwDirectory.Items.Clear(); DirectoryInfo dir = new DirectoryInfo(this.cmbDrive.SelectedValue.ToString()); foreach (DirectoryInfo dr in dir.GetDirectories()) { MyTreeViewItem tvi = new MyTreeViewItem(); tvi.Header = dr.Name; tvi.Path = dr.FullName; tvi.Type = dr.GetType().Name; tvi.Expanded += new RoutedEventHandler(Ctvi_Expanded); if (!dr.Attributes.ToString().Contains("Hidden")) { try { foreach (DirectoryInfo cdir in dr.GetDirectories()) { MyTreeViewItem ctvi = new MyTreeViewItem(); ctvi.Expanded += new RoutedEventHandler(Ctvi_Expanded); ctvi.Header = cdir.Name; ctvi.Path = cdir.FullName; ctvi.Type = cdir.GetType().Name; tvi.Items.Add(ctvi); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } this.tvwDirectory.Items.Add(tvi); } } btn_ConvertJson.IsEnabled = true; foreach (FileInfo FL in dir.GetFiles()) { this.ltbExplorer.Items.Add(FL.Name); } }
//Перехід по папках та вибір папки для конверсії в Json private void tvwDirectory_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (e.NewValue != null) { this.ltbExplorer.Items.Clear(); MyTreeViewItem tvi = (MyTreeViewItem)e.NewValue; DirectoryInfo dir = new DirectoryInfo(tvi.Path); sourceDir = dir; foreach (DirectoryInfo FD in dir.GetDirectories()) { ltbExplorer.Items.Add(FD.Name); } DirectoryInfo DIRF = new DirectoryInfo(tvi.Path); foreach (FileInfo FL in DIRF.GetFiles()) { ltbExplorer.Items.Add(FL.Name); } } e.Handled = true; }