计算c#中特定目录中文件夹内的文件数

时间:2015-10-03 14:23:05

标签: c#

我正在用c#编写一个程序。假设我在 Environment.CurrentDirectory 中有一些文件夹。文件夹以不同的数字命名(例如:1,2,3等)。每个文件夹里面都有一些文件。我想计算特定文件夹中的文件总数(比如文件夹' 1'),我该怎么做?

1 个答案:

答案 0 :(得分:1)

这应该有效。 "路径"包含所需文件夹的确切路径。

int fileCount = Directory.GetFiles(path).Count();

这就是你如何组合路径:

string path = Path.Combine(Environment.CurrentDirectory, "1");