计算某一路径下的所有目录或是文件数量,可以参考下面代码示例:
计算某一路径下的所有目录或是文件数量

 

不管是计算目录或理文件,2个方法均带2个参数,前者是传入的是物理路径,第二个传的是布尔值的参数,即是说可以计算是否包含子目录。

目录:

 public static int DirectoryCount(string physicalPath, bool isIncludeSubDirectory)
        {
            int count = 0;
            if (isIncludeSubDirectory)
                count = Directory.GetDirectories(physicalPath, "*", SearchOption.AllDirectories).Length;
            else
                count = Directory.GetDirectories(physicalPath, "*", SearchOption.TopDirectoryOnly).Length;
            return count;
        }
Source Code

相关文章:

  • 2022-01-07
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案