Friday 19 May 2017

Javascript Electron remove/ignore a certain item from a list

I am getting the filenames from a folder using the following code:

getFilenameList = () => {

    let select = document.getElementById("filenameSelect");

    let options = [];

    fs.readdirSync(folderUrl).forEach(file => { options.push(file) })

    for (let i = 0; i < options.length; i++) {

      let opt = options[i];
      let el = document.createElement("option");

      el.textContent = opt.replace(/\.[^/.]+$/, "");

      el.value = opt;

      console.log(opt);

      select.appendChild(el);

    }

  }

This is returning a list like this:

.DS_Store
filename1.html
filenameother.js
filenames.txt

The problem is that its also picking up unwanted files like: .DS_Store.

How can I fix this?



via dj2017

No comments:

Post a Comment