mirror of
https://github.com/unarray/file-tree-generator.git
synced 2026-07-22 08:40:29 +00:00
Add path utils
This commit is contained in:
parent
4b5a3b4889
commit
b4c092460a
2 changed files with 20 additions and 0 deletions
1
src/utils/path/index.ts
Normal file
1
src/utils/path/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./path";
|
||||
19
src/utils/path/path.ts
Normal file
19
src/utils/path/path.ts
Normal 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;
|
||||
};
|
||||
Loading…
Reference in a new issue