0

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 :)

Gabe
  • 13
  • 4

1 Answers1

1

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

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • `Most browsers will not ajax local files` - should that be `Most browsers will not access local files`? – Professor Abronsius Jul 15 '21 at 07:14
  • @ProfessorAbronsius see clarification – mplungjan Jul 15 '21 at 07:17
  • Similar question: [Reading all files in directory](https://stackoverflow.com/questions/10049557/reading-all-files-in-a-directory-store-them-in-objects-and-send-the-object) – Sana Mumtaz Jul 15 '21 at 07:43
  • This would be perfect, but from what I understood, Firefox doesn't have a full-fledged fs API; so for now I guess my only options are the input element or asking users to switch to Chrome. – Gabe Jul 15 '21 at 08:31