From 00eb77085c8fdde1f46fc5bed872611cc2c505f6 Mon Sep 17 00:00:00 2001 From: panoplied Date: Wed, 25 Jun 2025 02:25:58 +0300 Subject: [PATCH] add JS implementation of DFS example --- 07_trees/js/01_filesystem_dfs.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 07_trees/js/01_filesystem_dfs.js diff --git a/07_trees/js/01_filesystem_dfs.js b/07_trees/js/01_filesystem_dfs.js new file mode 100644 index 00000000..76670c5e --- /dev/null +++ b/07_trees/js/01_filesystem_dfs.js @@ -0,0 +1,19 @@ +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __path = path.dirname(__filename); + +function printnames(dir) { + for (const file of fs.readdirSync(dir).sort()) { + const fullPath = path.join(dir, file); + if (fs.statSync(fullPath).isFile()) { + console.log(file); + } else { + printnames(fullPath); + } + } +} + +printnames(path.join(__path, "pics"));