public FolderItem AddExistingFolder(FolderItem folderItem, string path) { if(this.Items[folderItem.Name]!=null) throw new Exception("There is already a folder with the same name"); this.Items.Add(folderItem); if (!Directory.Exists(folderItem.Path)) Directory.CreateDirectory(folderItem.Path); foreach (var subFolderPath in Directory.GetDirectories(path)) { folderItem.AddExistingFolder(new FolderItem() { Name = System.IO.Path.GetFileName(subFolderPath) }, subFolderPath); } foreach (var filePath in Directory.GetFiles(path)) { folderItem.AddExistingItem(new FileItem() { Name = System.IO.Path.GetFileName(filePath) }, filePath); } Solution.Modified = true; return folderItem; }
public FolderItem AddNewFolder(FolderItem item) { this.Items.Add(item); int i = 2; string newName = item.Name; while (Directory.Exists(item.Path)) item.Name = newName + " (" + (i++) + ")"; Directory.CreateDirectory(item.Path); Solution.Modified = true; return item; }