I have this directory structure:
folder
├───file.ext
├───A
│ └───a1.ext
└───B
└───b1.ext
And this script to read all the files in there:
import { join } from "$std/path/mod.ts";
async function readDirRecurse(dir) {
for await (const dirEntry of Deno.readDir(dir)) {
const subDir = join(dir, dirEntry.name);
console.log(dirEntry.name);
if (dirEntry.isFile) {
array.push(subDir);
} else if (dirEntry.isDirectory) {
readDirRecurse(subDir);
}
}
}
const array = [];
await readDirRecurse("./folder");
console.log("???? ~ result:", array);
The output:
A
B
file.ext
???? ~ result: [ "folder\file.ext" ]
a1.ext
b1.ext
My questions are:
- Why does the result is in the middle of the output, but not at the bottom?
- Why does it only contain the root file, not other files?