JaBa/utils/get-path.js
2024-12-06 23:58:15 +03:00

24 lines
524 B
JavaScript

import fs from "node:fs/promises";
import path from "node:path";
export const getFilePaths = async (directory, nesting) => {
let filePaths = [];
if (!directory) return;
const files = await fs.readdir(directory, { withFileTypes: true });
for (const file of files) {
const filePath = path.join(directory, file.name);
if (file.isFile()) {
filePaths.push(filePath);
}
if (nesting && file.isDirectory()) {
filePaths = [...filePaths, ...(await getFilePaths(filePath, true))];
}
}
return filePaths;
};