/// <summary> /// Jesli zaznaczony element jest plikiem kopiujemy go do folderu po lewej stronie /// Jesli jest folderem to tworzymy nowy folder i kopiujemy wszystkie jego pliki /// </summary> private void button7_Click(object sender, RoutedEventArgs e) { foreach (object k in listOfUserControls2.Children) { ElementsViews elementViews = (ElementsViews)k; if (elementViews.checkBox.IsChecked.Value) { if (elementViews.discElement is MyFile) { try { string fName = elementViews.discElement.Name; string path = elementViews.discElement.Path; File.Copy(path, System.IO.Path.Combine(directoryPath.Text, fName)); } catch (Exception) { MessageBox.Show("nie można skopiować pliku"); } } //----------------------------- else { try { string dirName = elementViews.discElement.Name; string pathx = System.IO.Path.Combine(directoryPath.Text, dirName); Directory.CreateDirectory(pathx); MyDirectory myDirectory1 = new MyDirectory(elementViews.discElement.Path); List <MyFile> subElements = myDirectory1.GetAllFiles(); foreach (MyFile file in subElements) { string fName = file.Name; File.Copy(file.Path, System.IO.Path.Combine(pathx, fName)); } } catch (Exception) { MessageBox.Show("Nie można skopiować folderu"); } } } } GenerateFilesList1(); }