1

I have a standard folder structure for a web app.

  • css
  • js
  • img
  • asetts
  • lib

index.html

Inside my assets folder I have a bunch of plain text files and I would like to first be able to list the filenames using Javascript, so I can store the URI's in the model, and read from them later on the in the application. I want all of this happening client side.

Allan Macmillan
  • 1,481
  • 3
  • 18
  • 30

2 Answers2

1

(Client-side) JavaScript does not have access to the file system like that.

This is not possible without some kind of browser plugin.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
0

You can read the textfiles in the local folder.

function read()
{
    var xHR = new XMLHttpRequest();
    //replace textfile_url with the relative url of your text file
    xHR.open("GET", "textfile_url", true);
    xHR.onreadystatechange = function ()
    {
        if(xHR.readyState === 4)
        {
            //all your text is in the next line
            var text = xHR.responseText;

        }
    }

    xHR.send();
}
zahreelay
  • 1,742
  • 12
  • 18