mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-01-01 16:23:02 +05:00
24 lines
524 B
JavaScript
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;
|
|
};
|