diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-11 14:24:49 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-11 14:24:49 -0700 |
| commit | 8c34d810af95fae0ef846f54370a8c88bfab7123 (patch) | |
| tree | 436beaf30f7b2b3f15741dd54a37e313964d1f7d /src/helper/get-directory-contents.ts | |
Diffstat (limited to 'src/helper/get-directory-contents.ts')
| -rw-r--r-- | src/helper/get-directory-contents.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/helper/get-directory-contents.ts b/src/helper/get-directory-contents.ts new file mode 100644 index 0000000..80fb20c --- /dev/null +++ b/src/helper/get-directory-contents.ts @@ -0,0 +1,34 @@ + + + +/*** EXPORT ------------------------------------------- ***/ + +export default async(directory: string): Promise<{ filename: string; }[]> => { + const documentArray: { filename: string; }[] = []; + + try { + const documents: Deno.DirEntry[] = []; + + for await (const dirEntry of Deno.readDir(directory)) { + if (dirEntry.isFile) + documents.push(dirEntry); + } + + documents.sort((a, b) => a.name.localeCompare(b.name)).reverse(); + + for (const document of documents) { + if (document.name.startsWith(".")) + return []; + + if (document.name.endsWith(".txt")) { + const data = { filename: document.name }; + documentArray.push(data); + } + } + } catch(error) { + console.error(`Error reading directory contents: ${String(error)}`); + } finally { + // deno-lint-ignore no-unsafe-finally + return documentArray; + } +} |
