21 lines
497 B
TypeScript
21 lines
497 B
TypeScript
export const readDirFiles = async (path: string) => {
|
|
return readDirFiltered(path, (file) => file.isFile);
|
|
};
|
|
|
|
export const readDirDirs = async (path: string) => {
|
|
return readDirFiltered(path, (file) => file.isDirectory);
|
|
};
|
|
|
|
export const readDirFiltered = async (
|
|
path: string,
|
|
filter: (file: Deno.DirEntry) => boolean,
|
|
) => {
|
|
const files: string[] = [];
|
|
for await (const file of Deno.readDir(path)) {
|
|
if (filter(file)) {
|
|
files.push(file.name);
|
|
}
|
|
}
|
|
return files;
|
|
};
|