void CreateFloder(string[] names, int index, Floder f, int max) { if (index > max) { return; } if (f == null) { return; } Node n = f.GetChildByName(names[index]); if (n != null) { if (n is Floder childF) { index++; CreateFloder(names, index, childF, max); } else if (n is Symlink s) { if (s.target.nodeType == 1) { Floder tarF = s.target as Floder; index++; CreateFloder(names, index, tarF, max); } } else { Console.WriteLine("不可在文件下创建目录"); return; } } else { Floder ff = CreateNode(1, names[index], f) as Floder; index++; CreateFloder(names, index, ff, max); } }
/// <summary> /// 用namelist找文件夹 /// </summary> Node FindFloderWithName(Node start, string[] names, bool isFullPath, bool isMatch = false) { Floder fo = start as Floder; if (fo == null) { return(null); } int tmp = isFullPath ? 1 : 0; int count = names.Length; if (count == 1 && isFullPath) //绝对路径只有一个结点 { return(fo); } Node n = fo.GetChildByName(names[tmp], isMatch); if (names.Length > tmp + 1) { for (int i = tmp + 1; i < names.Length; i++) { if (i == names.Length - 1) //最后一个结点 { if (n != null) { if (n is Floder f) //找到文件夹继续找 如果是最后一个结点了,返回这个文件或者文件夹 { n = f.GetChildByName(names[i], isMatch); return(n); } else if (n is Symlink s && s.target != null) //找到符号链接 看目标是不是文件夹 { n = SymlinkFinalReturnNode(s); if (n is Floder f1) { n = f1.GetChildByName(names[i], isMatch); return(n); } } } else { return(null); } } else //不是最后一个 { if (n != null) { if (n is Floder f) //找到文件夹继续找 { n = f.GetChildByName(names[i], isMatch); } else //找到个文件,不正常情况,路径错误 { Console.WriteLine("路径不存在"); return(null); } } else //没找到 { return(null); } } } } else //如果只有1个结点 { if (n != null) { return(n); //如果是最后一个结点了,返回这个文件或者文件夹 } else { return(null); } } return(null); }