首页 > 其他 > 详细

计算某一路径下的所有目录或是文件数量

时间:2017-04-23 23:46:18      阅读:252      评论:0      收藏:0      [点我收藏+]

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

 

不管是计算目录或理文件,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


文件:

技术分享
 public static int FileCount(string physicalPath, bool isIncludeSubDirectory)
        {
            int count = 0;
            if (isIncludeSubDirectory)
                count = Directory.GetFiles(physicalPath, "*.*", SearchOption.AllDirectories).Length;
            else
                count = Directory.GetFiles(physicalPath, "*.*", SearchOption.TopDirectoryOnly).Length;
            return count;
        }
Source Code

 

计算某一路径下的所有目录或是文件数量

原文:http://www.cnblogs.com/insus/p/6754571.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!