Сам разобрался, может кому-то будет полезно, вот готовый код, выполнять в кубике node.js (я выполнял в node18) .... кстати, больше 80% кода сгенерирована нейронкой https://chat.openai.com/chat
Задача выполняется двумя кубиками node.js
1) Сначала ищем из каталога все папки и переворачиваем этот список . Полученный список сохраняем в [[SPISOK]]
// Step 1
// Get the path to the "D:\\2 отправленое\\АНАЛИЗ" folder
const path = "D:\\2 отправленое\\АНАЛИЗ";
// Create an empty list to store the paths to the folders inside the "creep-analysis" folder
let spisok = [];
// Use the fs (file system) module to read the contents of the "creep-analysis" folder
const fs = require('fs');
const files = fs.readdirSync(path);
// Loop through the contents of the "creep-analysis" folder and add the paths to the folders to the "spisok" list
files.forEach((file) => {
// Check if the current item is a folder
if (fs.lstatSync(path + '/' + file).isDirectory()) {
// Add the path to the folder to the "spisok" list
spisok.push(path + '/' + file);
}
});
// Step 2
// Sort the "spisok" list in descending order by the number that each folder name starts with
spisok.sort((a, b) => {
// Get the folder name from the path of each item in the list
const folderNameA = a.split('/').pop();
const folderNameB = b.split('/').pop();
// Extract the number that each folder name starts with
const numberA = parseInt(folderNameA.match(/^\d+/)[0]);
const numberB = parseInt(folderNameB.match(/^\d+/)[0]);
// Compare the numbers and sort the list in descending order
return numberB - numberA;
});
// Step 3
// Save the sorted "spisok" list to the "itog" variable
[[SPISOK]] = spisok;
2) Далее ищем папку которая имеет вес меньше 1 мб и при условии что в каталоге где она лежит следующей будет папка с весом >=100мб
Готовый рабочий код, полный путь к итоговой папке сохраняется в [[PYT_K_PROSHLOY_PYSTOY_PAPKE]]:
// Declare the list "spisok"
let spisok = [[SPISOK]];
const fs = require('fs');
// Use a for loop to go through all elements of the list "spisok"
for (let i = 0; i < spisok.length; i++) {
let folderPath = spisok[i]; // Assign each value of the loop to the variable "folderPath"
//console.log(folderPath); // Print the value of "folderPath" in the log
// шаг 1. начитаем получать размер папки путь к ней лежит в folderPath
function getFolderSize(path) {
let totalSize = 0;
const files = fs.readdirSync(path);
for (let i = 0; i < files.length; i++) {
const stats = fs.statSync(path + '//' + files[i]);
if (stats.isFile()) {
totalSize += stats.size;
}
else if (stats.isDirectory()) {
totalSize += getFolderSize(path + '//' + files[i]);
}
}
return totalSize;
}
const folderSize = getFolderSize(folderPath);
// закончили получать размер папки "folderPath"
// и размер записали в "folderSize"
if (folderSize < 1000000); {
// шаг 2. получаем размер папки лежащей ниже
let nextElement = spisok[i + 1];
function getFolderSize(path) {
let totalSize = 0;
const files = fs.readdirSync(path);
for (let i = 0; i < files.length; i++) {
const stats = fs.statSync(path + '//' + files[i]);
if (stats.isFile()) {
totalSize += stats.size;
}
else if (stats.isDirectory()) {
totalSize += getFolderSize(path + '//' + files[i]);
}
}
return totalSize;
}
const nextFolderSize = getFolderSize(nextElement);
// закончили получать размер папки лежащей ниже и запись
// записали размер в "nextFolderSize"
if (nextFolderSize > 100000000) {
console.log(folderPath);
//console.log(folderSize);
//console.log(folderPath);
[[PYT_K_PROSHLOY_PYSTOY_PAPKE]] = folderPath;
break
}
}
}