From 8c34d810af95fae0ef846f54370a8c88bfab7123 Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Sat, 11 Apr 2026 14:24:49 -0700 Subject: initial commit --- src/helper/get-directory-contents.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/helper/get-directory-contents.ts (limited to 'src/helper/get-directory-contents.ts') 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; + } +} -- cgit v1.2.3