Add path utils

This commit is contained in:
Unarray 2023-08-23 15:10:29 +02:00
parent 4b5a3b4889
commit b4c092460a
2 changed files with 20 additions and 0 deletions

1
src/utils/path/index.ts Normal file
View file

@ -0,0 +1 @@
export * from "./path";

19
src/utils/path/path.ts Normal file
View file

@ -0,0 +1,19 @@
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;
};