C#非递归 获取子文件夹和文件列表
. public Dictionary<string, int> GetFileNum(string srcPath) . { . Dictionary<string, int> dic = new Dictionary<string, int>(); . string[] folders = System.IO.Directory.GetDirectories(srcPath);//GetFileSystemEntries(srcPath); . foreach (string folder in folders) . { . string[] files = System.IO.Directory.GetFiles(folder); . dic.Add(folder, files.Length); . . } . return dic; . } foreach (var i in v) . Console.WriteLine(i);
代码直接在C# interactive 里运行,不用新建项目。