Created
February 11, 2025 22:54
-
-
Save jswhisperer/80496059583d48d895f5a5c0ae77acf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listDirectoryContents = async (directoryHandle, depth) => { | |
depth = depth || 1; | |
directoryHandle = directoryHandle || await navigator.storage.getDirectory(); | |
const entries = await directoryHandle.values(); | |
for await (const entry of entries) { | |
// Add proper indentation based on the depth | |
const indentation = ' '.repeat(depth); | |
if (entry.kind === 'directory') { | |
// If it's a directory, log its name | |
// and recursively list its contents | |
console.log(`${indentation}${entry.name}/`); | |
await listDirectoryContents(entry, depth + 1); | |
} else { | |
// If it's a file, log its name | |
console.log(`${indentation}${entry.name}`); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment