From b4c092460a2f7ebb8daa4cea1c1e0784d6666a6f Mon Sep 17 00:00:00 2001 From: Unarray <48868686+Unarray@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:10:29 +0200 Subject: [PATCH] Add path utils --- src/utils/path/index.ts | 1 + src/utils/path/path.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/utils/path/index.ts create mode 100644 src/utils/path/path.ts diff --git a/src/utils/path/index.ts b/src/utils/path/index.ts new file mode 100644 index 0000000..1af1246 --- /dev/null +++ b/src/utils/path/index.ts @@ -0,0 +1 @@ +export * from "./path"; \ No newline at end of file diff --git a/src/utils/path/path.ts b/src/utils/path/path.ts new file mode 100644 index 0000000..d8485a5 --- /dev/null +++ b/src/utils/path/path.ts @@ -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 => { + 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; +}; \ No newline at end of file