private void AddFilePath(FileItem item, FolderNode folder) { var paths = item.FilePath.Split(new char[] { '/', '\\' }); Console.WriteLine(paths.Length); if (paths.Length == 1) { folder.Nodes.Add(new FileNode() { Text = paths[0], Tag = item }); return; } for (int i = 0; i < paths.Length - 1; i++) { bool found = false; foreach (var v in folder.Nodes) { if (v is FolderNode fod && fod.Text == paths[i]) { folder = fod; found = true; break; } } if (!found) { var newf = new FolderNode() { Text = paths[i] }; folder.Nodes.Add(newf); folder = newf; } } folder.Nodes.Add(new FileNode() { Text = paths[paths.Length - 1], Tag = item }); }