Dzwebs.Net

撰写电脑技术杂文十余年

遍历某文件夹下的图片名称

Admin | 2016-7-7 7:23:04 | 被阅次数 | 3672

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  下面这段代码的功能是,遍历服务器某文件夹下的所有图片,返回其名称。

   DirectoryInfo Dir=new DirectoryInfo(DirPath);
        try
        {
            foreach(FileInfo f in Dir.GetFiles("*.jpg")) //查找文件
            {
                Response.Write(f.ToString()+"
");
            }
        }
        catch(Exception e)
        {
            Response.Write(e.Message);
        }

  DirPath指的是路径,比如:Server.MapPath("Img/jpg")

  知识拓展:遍历子文件夹名称的代码

  DirectoryInfo Dir = new DirectoryInfo(DirPath);
        try
        {
            foreach(DirectoryInfo d in Dir.GetDirectories())//查找子目录
            {
                GetDirName(Dir+"\\"+d.ToString());
                Response.Write(Dir +"\\"+ d.ToString()+"<br>");
            }
        }
        catch (Exception e)
        {
            Response.Write(e.Message+"<br>");
        }


该杂文来自: 网站开发杂文

上一篇:asp.net遍历文件夹或文件

下一篇:asp.net遍历子文件夹的名称

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计