public void DirectoryDelete(string path, bool recursive) { if (!IsPathInCone(path, out string processedPath)) { //TODO: handle cases where a portion of what would be deleted is inside our cone // and parts are outside _basis.DirectoryDelete(path, recursive); return; } path = processedPath; string rel = path.Substring(_root.FullPath.Length).Trim('/', '\\'); if (string.IsNullOrEmpty(rel)) { return; } string[] parts = rel.Split('/', '\\'); FileSystemDirectory currentDir = _root; FileSystemDirectory parent = null; for (int i = 0; i < parts.Length; ++i) { parent = currentDir; FileSystemDirectory dir; if (!currentDir.Directories.TryGetValue(parts[i], out dir)) { return; } currentDir = dir; } if (!recursive && (currentDir.Directories.Count > 0 || currentDir.Files.Count > 0)) { throw new IOException("Directory is not empty"); } parent.Directories.Remove(currentDir.Name); }