0

I'm trying to display ~500 files in 50 subfolders on one HTML page on my laptop. Files change often enough it's no use if it's not dynamic.

Below is from my main.js. It all works. Local links and all but how can I get a list of files from my laptop through my browser? I figured I could with javascript but no luck yet.

// where are we?
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
document.write(loc + '<br>');
document.write(dir);


// make links from a list passed to it
function MakeLinks2(files) {
    var text = "";
    var i;
        text += '</ul>';
            for (i = 0; i < files.length; i++) {
              text += '<li><a href="pdfs/' + files[i] + '">' + files[i] + '</a></li>';
            }
        text += '</ul>';
        document.getElementById("external").innerHTML = text;
}

window.onload = MakeLinks2(["1.pdf", "2.pdf", "3.pdf", "4.pdf", "1.pdf", "2.pdf", "3.pdf", "40.pdf"]);
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
dn13
  • 1
  • Does this answer your question? [How to get the contents of the directory from local PC in javascript](https://stackoverflow.com/questions/13624450/how-to-get-the-contents-of-the-directory-from-local-pc-in-javascript) – caramba Nov 29 '20 at 12:03
  • Browser doesn't allow reading local files directly using JavaScript. You would wanna create an upload feature where the users can drop the files. Then store it in the backend and read each one of them. Eg: Google Drive – Vishnudev Krishnadas Nov 29 '20 at 12:03
  • thx Vishnudev. I have no backend to work with tho. its all existing local file structure. – dn13 Nov 30 '20 at 15:07
  • thx caramba. I've looked into a few similar ideas. I will try this when i get some time. thanks for your suggestion.. – dn13 Nov 30 '20 at 15:10

0 Answers0