Dzwebs.Net

撰写电脑技术杂文十余年

asp.net遍历子文件夹的名称

Admin | 2016-7-8 11:17:34 | 被阅次数 | 4877

温馨提示!

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

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

  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>");
        }

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

  代码演示结果如下图。


  知识拓展:遍历图片名称的代码

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


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

上一篇:遍历某文件夹下的图片名称

下一篇:vs2005代码空白中出现...点点点

网站备案号:

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

版权属性:

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

联系方式:

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