Couldn't send variable to function


This code find file names in text file, and then trying to find files by name in specified directory. files name is array of strings. For example

nameArr in console [“Реклама - Макси дек_скидки0514.mp3”, “Реклама - Краснодар Центр Города и Новый Горизонт.mp3”]

nameArr[0] in colsole "Реклама - Макси дек_скидки0514.mp3"

trying to find files

find.fileSync(nameArr[0], ‘E:/transfer’) as result [] - empty array

when I give arg “manually” all work as expected

find.fileSync(“Реклама - Макси дек_скидки0514.mp3”, ‘E:/transfer’) as result [“E:\transfer*Реклама - Макси дек_скидки0514.mp3*”]

so I can’t understand, why function doesn’t work with nameArr[0]

code examle

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 = []; //names of the files

nameArrayButton.addEventListener('click', ()=>{
  find.fileSync(nameArr[0], "E:/transfer");

openButton.addEventListener('click', () => {

openInput.addEventListener('change', handleFileSelect);

function handleFileSelect(e) {
  let file =[0];
  let reader = new FileReader();

  reader.onload = function (e) {//parsing the text file and find names on it
    string =;
    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);

  return newArray;

function nameReturn(result) {
  result.forEach(function(item) {
    let pt = path.parse(item).base;


Can you please edit you post (or make a new comment below) that has the code, but marked properly (either click </> or wrap it in triple backticks; you’ll see if it worked by looking at the preview)


Sorry, I’ve done