private int GetFilesCount(System.IO.DirectoryInfo dirInfo)
{
int totalCount = 0;
totalCount += dirInfo.GetFiles().Length;
foreach (System.IO.DirectoryInfo subdir in dirInfo.GetDirectories())
{
totalCount += GetFilesCount(subdir);
}
return totalCount;
}
这段代码是一个递归函数,用于计算指定目录及其所有子目录中的文件总数。它首先计算当前目录的文件数量,然后对每个子目录调用自身进行递归计数,最后返回累计的总文件数。
925

被折叠的 条评论
为什么被折叠?



