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"]);
4
  • Does this answer your question? How to get the contents of the directory from local PC in javascript Commented Nov 29, 2020 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 Commented Nov 29, 2020 at 12:03
  • thx Vishnudev. I have no backend to work with tho. its all existing local file structure. Commented Nov 30, 2020 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.. Commented Nov 30, 2020 at 15:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.