При чтении файла строка за строкой с кодом ниже.Кажется, что строка не читается правильно?
Часть строки в каждой строке файла:* b53pd4574z8pe9x793go 1004 *
console.log (pathcreatefile) правильно показывает:* b53pd4574z8pe9x793go 1008 *
Но похоже, что: fs.promises.writeFile это делает ?: b53'd4574z8pe9x793go
Ошибка консоли: (узел: 1148) UnhandledPromiseRejectionWarning: Ошибка: ENOENT: нет такого файла или каталога, откройте 'C: \ myproject \ instances \ b53'd4574z8pe9x793go \ folder \ testA.txt
Мой коднижеприведенное.Я добавил 3 строки, которые я прочитал из файла в коде:
'use strict';
const fs = require('fs');
var i;
//1|one/a|test1|C:/myproject/instances/b53pd4574z8pe9x793go/folder/testA.txt
//1|two/b|test2|C:/myproject/instances/b53pd4574z8pe9x793go/folder/testB.txt
//1|three/c|test3|C:/myproject/instances/b53pd4574z8pe9x793go/folder/testC.txt
var textarray = fs.readFileSync("C:/myproject/folder/testfile.txt").toString('utf-8').split("\n"); //Read the file
(async () => {
var thePromises = []
for (i = 0; i < textarray.length; i++) {
//1|one/a|test1|C:/myproject/instances/b53pd4574z8pe9x793go/folder/testA.txt
const line = textarray[i].split("|")
if (line.length == 4) {
const pathcreatefile = line[3] //C:/myproject/instances/b53pd4574z8pe9x793go/folder/testA.txt
console.log(pathcreatefile)
try {
let tickerProcessing = new Promise(async (resolve) => {
await fs.promises.writeFile(pathcreatefile, "hello")
resolve()
})
thePromises.push(tickerProcessing)
} catch (e) {
console.error(e)
}
}
}
// wait for all of them to execute or fail
await Promise.all(thePromises)
})()