UNPKG

axiodb

Version:

The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor

49 lines 2.24 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = countFilesRecursive; const promises_1 = __importDefault(require("node:fs/promises")); const node_path_1 = __importDefault(require("node:path")); /** * Recursively counts the number of files in a folder and its subfolders. * * This function traverses through the directory structure starting from the provided folder path * and counts all files encountered during the traversal. It does not count directories themselves. * * @param folderPath - The path to the folder to count files in * @returns A promise that resolves to the total number of files found * * @example * ```typescript * const count = await countFilesRecursive('/path/to/folder'); * console.log(`Total files: ${count}`); * ``` */ function countFilesRecursive(folderPath) { return __awaiter(this, void 0, void 0, function* () { let count = 0; const items = yield promises_1.default.readdir(folderPath, { withFileTypes: true }); for (const item of items) { const fullPath = node_path_1.default.join(folderPath, item.name); if (item.isFile()) { count++; } else if (item.isDirectory()) { count += yield countFilesRecursive(fullPath); } } return count; }); } //# sourceMappingURL=filesCounterInFolder.helper.js.map