Since javascript in the browser cannot directly access the serverβs file system, you will probably need some server-side scripts, such as PHP, Perl, ASP, etc., to send the contents of the file system to a web page (possibly via Ajax), and then have the javascript format of the contents of the file system in the desired format, say, using the file tree management in this answer: https://stackoverflow.com/a/9057959/74585
If you cannot use server-side scripts, perhaps you could hard code the categories in the javascript file (assuming the categories change not very often) and the number of images in sequence? Then your javascript can simply search for images, trying to load the folder and image category number. Then determine when the image does not load using onerror and stops displaying the previous / next buttons.
An even more left-handed field solution that does not require server-side scripting may be to create a script, say, with perl, on your workstation that connects via FTP, scans all folders and files and creates a JSON or XML file containing the file contents system. Then your javascript can call this generated file and access the file system. The downside is that you need to restart the script workstation every time you want to add another file.
source share