1

I. I´m trying to make a skeleton of a app to read and write files in Neutralino.js but...

Now i´m stopped by trying to read the content of a selected file to a variable. I think the file is corrected selected, but... when using the Neutralino.filesystem.readFile it reads the text file whitout respecting the end of line carriege.

The conteudo_edm contains all the file content but just as a string, hope to be like a array, but there is no line breaks...

Any ideia?

async function lerN() {
let entries = await Neutralino.os.showOpenDialog('Abrir um ficheiro', {
    filters: [
        { name: 'ISPOL', extensions: ['edm', 'EDM'] },
        { name: 'All files', extensions: ['*'] }
    ]
});

ficheiro = entries + ''

ficheiro = ficheiro.replace(/\\/g, "/")

conteudo_edm = await Neutralino.filesystem.readFile(entries[0]); //Aqui está a juntar tudo numa string!!!

console.log(conteudo_edm)



document.getElementById("lbl_ficheiroaberto").textContent = "Ficheiro aberto : " + ficheiro;
console.log("entries__")
console.log(entries)
console.log("entries__")

filtra_ficheiro(entries[0])

//document.getElementById("lbl_apagar").textContent = "estou a ler: " + ficheiro

}

José
  • 33
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 17 '22 at 13:27

1 Answers1

1

Try Using Split Instead Of Replace.

This Worked For Me:

async function lerN() {
    let entries = await Neutralino.os.showOpenDialog('Abrir um ficheiro', {
        filters: [
            { name: 'ISPOL', extensions: ['edm', 'EDM'] },
            { name: 'All files', extensions: ['*'] }
        ]
    });
    ficheiro = entries + ''
    ficheiro = ficheiro.split(/\r?\n/); # This is what i tried.
    conteudo_edm = await Neutralino.filesystem.readFile(entries[0]);
    console.log(conteudo_edm)
    document.getElementById("lbl_ficheiroaberto").textContent = "Ficheiro aberto : " + ficheiro;
    console.log("entries__")
    console.log(entries)
    console.log("entries__")
    filtra_ficheiro(entries[0])
}
Aditya
  • 1,132
  • 1
  • 9
  • 28