html - Scan folder content in Javascript - Stack Overflow

admin2025-04-09  1

I am trying to build an HTML5 video player that will automatically turn on playlist mode if there is more than one video file in the /videos folder.

I'm trying not to use PHP for this so please keep that in mind when suggesting something.

Thank you.

I am trying to build an HTML5 video player that will automatically turn on playlist mode if there is more than one video file in the /videos folder.

I'm trying not to use PHP for this so please keep that in mind when suggesting something.

Thank you.

Share Improve this question asked Sep 10, 2015 at 19:10 diederikdiederik 1411 gold badge3 silver badges8 bronze badges 2
  • 2 There is no way to "list" remote files in JavaScript, except as exposed by the server. In this case the best method would be to ask the server to provide the information somehow. – user2864740 Commented Sep 10, 2015 at 19:12
  • Anyway. this could also be done via convention, ie. video1.mpg, video2.mpg, videoN.mpg .. in which case the resource names are guessed - well, just checked in sequence - until one fails to load. Not that I remend it, but it does avoid the need to "list" resources. – user2864740 Commented Sep 10, 2015 at 19:14
Add a ment  | 

1 Answer 1

Reset to default 3

You cannot access file-system using JavaScript. But, you can do a fake HTTP request to the directory with index access:

var dir = "/videos";
var fileextension = ".mp4";
$.ajax({
    //This will retrieve the contents of the folder if the folder is configured as 'browsable'
    url: dir,
    success: function (data) {
        // List all mp4 file names in the page
        $(data).find("a:contains(" + fileextension + ")").each(function () {
            var filename = this.href.replace(window.location.host, "").replace("http:///", "");
            $("body").append($("<img src=" + dir + filename + "></img>"));
        });
    }
});
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744203683a235919.html

最新回复(0)