Number of folder inside a directory

后端 未结 3 1607
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 15:59

How do I know the number of folders inside a directory?

I try using System.IO.Directory but no luck.

3条回答
  •  死守一世寂寞
    2020-12-10 16:41

    Use:

    Directory.GetDirectories(@"C:\").Length
    

    of course instead of @"C:\" you use whatever path you want to know the sub-directory count for. The method also has overloads to allow searching for a specific pattern and searching recursively.

提交回复
热议问题