码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-04-24 00:10:30      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:isp   count   log   物理   director   方法   string   code   arc   

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

 

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

 

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

标签:isp   count   log   物理   director   方法   string   code   arc   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!