Gabe
Gabe

Reputation: 13

How to read an unknown number of files from HTML's own directory

What I have here is a simple code that creates an object then provides a simple GUI for users to make changes to said object. When they're done, the program spits out a JSON string to be saved. This code runs locally on a browser, with no online interactions or file transfers.

My question is: Is it possible for the application to load an unknown amount of JSON files if they were placed by the user in the HTML's own directory? I already know the input tag can be used to upload multiple files, but I'm looking for something more automatic, where all the user needs to do is place the files in a specific folder for them to be read.

To illustrate

Folder/
    subfolder1/
    subfolder2/
    files_go_here/
        file01.json
        file02.json
        ...
        file99.json
    index.html
    script.js

As a beginner I'm writing this code to learn and improve, so please no Node.js, jQuery, or anything of the sort (my brain isn't ready yet). All I need to know is if it's possible, though a point in the right direction would be nice.

Thanks for reading :)

Upvotes: 0

Views: 130

Answers (1)

mplungjan
mplungjan

Reputation: 178094

We normally use Ajax to access files like JSON in a browser.

Most browsers will NOT acces local files when the html file you use is loaded from a server.

If the html file is loaded from file system it can access via the file system

Node.js is JavaScript and it uses the fs file system too,
for example Reading all files in a directory, store them in objects, and send the object, so don't be scared of that

Upvotes: 1

Related Questions