Given: I am writing an application on Electron, there is a text file from which you need to get an array of names. Array successfully received, can be displayed in the console. console.log (array [0]) Advertising - ALESA04032016.mp3

When transferring an element of this array as an argument to a function (or similar for working with the file system) find.fileSync (array [0], "D: / transfer") we get an empty array at the output []

However : find.fileSync ("Advertising - ALESA04032016.mp3", "D: / transfer") everything is fine at the output ["D: \ transfer \ roliki \ rolikiNOW \ Advertising - ALESA04032016.mp3"]

And when creating an array in "manually", for example, let array = ["Advertising - ALESA04032016.mp3", "Advertising - City Center 31 08 17 (Fish) .mp3"], find.fileSync (array [0], " D: / transfer ") at the output everything is also ok [" D: \ transfer \ roliki \ rolikiNOW \ Advertising - ALESA04032016.mp3 "]

Link https://github.com/crocodeev/electronTester

Code

const searcher = require('string-search'); const path = require('path'); const fs = require('fs'); const find = require('find'); let openButton = document.getElementById('openButton'); let openInput = document.getElementById('openInput'); let nameArrayButton = document.getElementById('nameArray') let nameArr = []; nameArrayButton.addEventListener('click', () => { console.log(nameArray); }); openButton.addEventListener('click', () => { openInput.click() }); openInput.addEventListener('change', handleFileSelect); function handleFileSelect(e) { let file = e.target.files[0]; let reader = new FileReader(); reader.onload = function (e) { string = e.target.result; searcher.find(string, "Реклама") .then(result => arrayRebuilder(result)) .then(result => nameReturn(result)) } reader.readAsText(file, "windows-1251"); } function arrayRebuilder(array) { let newArray = []; for (let i = 0; i < array.length; i++) { let editFilePath = array[i].text.slice(9, array[i].length); newArray.push(editFilePath); } return newArray; } function nameReturn(result) { result.forEach(function(item) { let pt = path.parse(item).base; nameArr.push(pt) }) } 

    0