℡Wang Yan 2016-05-12 18:55 采纳率: 100%
浏览 187

获取服务器子文件夹列表

Is there a way to give jquery a path and it would return list of all subfolders in given path?

I have this, which returns all pics from the folder:

var folder = "photos/";
          $.ajax({
              url : folder,
              success: function (data) {
                  $(data).find("a").attr("href", function (i, val) {
                      if( val.match(/\.(jpe?g|png|gif)$/) ) {
                          $('#links').append(
                            '<a href="' + folder + val + '" title="' + val + '">' +
                            '<img src="' + folder + val +'" class="photos"></a>'
                            );
                      }
                  });
              }
          });

Just need proper regexp for "ends with /"

  • 写回答

1条回答 默认 最新

  • 乱世@小熊 2016-05-12 19:50
    关注

    Is there a way to give jquery a path and it would return list of all subfolders in given path?

    Every webserver will return this information in a different format, and some will not return such information at all.

    Just need proper regexp for "ends with /"

    Ah, OK. Replace val.match(/\.(jpe?g|png|gif)$/) with val.match(/\/$/) and then it will look for a trailing / character.

    $ represents end of string. \/ is an escaped / character because / normally represents the beginning and end of the regex.

    I think if you used regex tag and title you may have gotten this answer more quickly. :-)

    评论

报告相同问题?