//zwraca tablice instacji folderow i plikow w danej sciezce public FolderOrFile[] SetFiles(string[] drive, string path) { System.IO.DriveInfo di = new System.IO.DriveInfo(drive[0]); if (di.IsReady) { string[] tmp = Directory.GetDirectories(path); FolderOrFile[] folders = new FolderOrFile[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { folders[i] = new FolderOrFile(tmp[i]); } tmp = Directory.GetFiles(path); FolderOrFile[] files = new FolderOrFile[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { files[i] = new FolderOrFile(tmp[i]); } FolderOrFile[] all; if (path == drive[0]) { all = new FolderOrFile[folders.Length + files.Length]; Array.Copy(folders, all, folders.Length); Array.Copy(files, 0, all, folders.Length, files.Length); } else { all = new FolderOrFile[folders.Length + files.Length + 1]; all[0] = new FolderOrFile("📂", "[..]", Path.GetDirectoryName(path)); Array.Copy(folders, 0, all, 1, folders.Length); Array.Copy(files, 0, all, folders.Length + 1, files.Length); } Console.WriteLine("zwraca cos nowego"); return(all); } else { Console.WriteLine("Zwraca pusta"); return(new FolderOrFile[0]); } }
public void Copy(int index, FolderOrFile[] filesSource, string destinationPath) { if (System.IO.Directory.Exists(filesSource[index].PathOf) && System.IO.Directory.Exists(destinationPath)) { //kopiowanie folderu try { if (!Directory.Exists(destinationPath + "\\" + filesSource[index].NameOf)) { Directory.CreateDirectory(destinationPath + "\\" + filesSource[index].NameOf); string[] tmp = Directory.GetDirectories(filesSource[index].PathOf); FolderOrFile[] folders = new FolderOrFile[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { folders[i] = new FolderOrFile(tmp[i]); //rekurencja wchodzaca w podfoldery Copy(i, folders, (destinationPath + "\\" + filesSource[index].NameOf)); } //kopiowanie plikow w folderach tmp = Directory.GetFiles(filesSource[index].PathOf); FolderOrFile[] files = new FolderOrFile[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { files[i] = new FolderOrFile(tmp[i]); System.IO.File.Copy(files[i].PathOf, (destinationPath + "\\" + filesSource[index].NameOf + "\\" + files[i].NameOf)); } } else { MessageBox.Show("Folder o takiej nazwie w sciezce docelowej juz istnieje"); } } catch (System.IO.IOException e) { MessageBox.Show(e.Message); } } else if (System.IO.File.Exists(filesSource[index].PathOf) && System.IO.Directory.Exists(destinationPath)) { //kopiowanie pliku try { System.IO.File.Copy(filesSource[index].PathOf, (destinationPath + "\\" + filesSource[index].NameOf)); } catch (System.IO.IOException e) { MessageBox.Show(e.Message); } } else { if ((filesSource[index].Type) == "📄") { MessageBox.Show("Blad! Wybrany plik nie istnieje"); } else { MessageBox.Show("Blad! Wybrany folder nie istnieje"); } if (!System.IO.Directory.Exists(destinationPath)) { MessageBox.Show("Blad! Sciezka docelowa nie istnieje"); } } }