Показать сообщение отдельно
  #1 (permalink)  
Старый 16.12.2022, 10:42
Кандидат Javascript-наук
Отправить личное сообщение для mik888em Посмотреть профиль Найти все сообщения от mik888em
 
Регистрация: 21.06.2020
Сообщений: 142

Найти пустую папку. Ошибка в коде?
Есть список , в нём пути к папкам. Нужно найти первую пустую (меньше 1 мб) папку и записать путь к ней в перем itog , но должно выполняться условие что после неё стоит папка размером 100мб или больше.

Написал код, выполняю в nodejs, но получаю ошибку:
ReferenceError: getFolderSize is not defined


Код:
// Step 1
const fs = require('fs');
const path = require('path');
const spisok = [[SPISOK]];

let pytkpystoypapke; // variable to store the path to the found folder
let itog; // variable to store the path to the found folder in step 2

for (let i = 0; i < spisok.length; i++) {
  let folder = spisok[i];
  let folderSize = getFolderSize(folder); // function to get the size of a folder, not provided in the question
  if (folderSize < 1000000) {
    if (i < spisok.length - 1) {
      let nextFolder = spisok[i + 1];
      let nextFolderSize = getFolderSize(nextFolder);
      if (nextFolderSize > 1000000) {
        pytkpystoypapke = folder;
        break;
      }
    }
  }
}

if (pytkpystoypapke) {
  itog = pytkpystoypapke;
}

// Now, the variable itog should contain the path to the found folder whose size is less than 1000000 bytes and the next folder has a size greater than 1000000 bytes.
Ответить с цитированием