Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions 07_trees/js/01_filesystem_dfs.js
Original file line number Diff line number Diff line change
@@ -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"));