ITPub博客

首页 > IT职业 > IT生活 > 计算目录下文件数

计算目录下文件数

IT生活 作者:w39 时间:2021-09-09 09:45:43 0 删除 编辑

学习C#的文件系统的Directory类。
比如,计算某目录下的文件数量:

图片描述

 

class Be    {        public string Path { get; set; }        public void GetPngFileList()        {                      if (!Directory.Exists(Path))            {                Console.WriteLine("指定的路径不存在。");            }            else            {                var files = Directory.GetFiles(Path, "*.*");                Console.WriteLine("总共{0}个文档。",files.Length);            }        }    }

Source Code

 

演示:

图片描述

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/854/viewspace-2811886/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-12-14

  • 博文量
    92
  • 访问量
    268574