mirror of
https://github.com/unarray/file-tree-generator.git
synced 2026-07-22 08:40:29 +00:00
19 lines
No EOL
508 B
TypeScript
19 lines
No EOL
508 B
TypeScript
import { readdir, stat } from "fs/promises";
|
|
import { sep as separator } from "path";
|
|
|
|
export const getFiles = async(path: string, filter: string[] = [], files: string[] = []): Promise<string[]> => {
|
|
const fileList = await readdir(path);
|
|
|
|
for (const file of fileList) {
|
|
const name = `${path}${separator}${file}`;
|
|
const entityStat = await stat(name);
|
|
|
|
if (entityStat.isDirectory()) {
|
|
await getFiles(name, filter, files);
|
|
} else {
|
|
files.push(name);
|
|
}
|
|
}
|
|
|
|
return files;
|
|
}; |