开发者

How to get sub-folder names from a given path Server.MapPath

I want get the folder names from server.MapPath in ASP.NET MVC 3 application. In this action, I have to check (if ther开发者_StackOverflow中文版e exist more folders in a given folder name) if a .jpg file is in that folder and if so, return that folder.

string path = Server.MapPath("Content/");
DirectoryInfo dInfo = new DirectoryInfo(path);
DirectoryInfo[] subdirs = dInfo.GetDirectories();

if (Directory.Exists(path))
{
    ArrayList ar = new ArrayList();
    // This path is a directory
    ar.Add(path);
    //ProcessDirectory(path);
}


I'm not sure I've understand the qestion correctly, but I think you want something like

string path = Server.MapPath(YOURPATH);
List<string> files = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);

or something like

string path = Server.MapPath(YOURPATH);
List<string> picFolders = new List<string>();

if(Directory.GetFiles(path, "*.jpg").Length > 0)
    picFolders.Add(path)

foreach(string dir in Directory.GetDirectories(path, "*", SearchOption.AllDirectories))
{
    if(Directory.GetFiles(dir, "*.jpg").Length > 0)
        picFolders.Add(dir)
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜