Convenience method for recursive directory iteration
Migrated from https://github.com/WICG/file-system-access/issues/173 (see https://github.com/whatwg/fs/issues/2)
It should be easy to read only files or subfolders from a parent folder, and have a recursive option to return the contents of subfolders. Example:
try {
for await(let file_reference of folder_reference.read({ files: true, folders: false, recursive: true })) {
console.log(file_reference)
}
} catch(error) {
console.error(error)
}
question: How would we deal with knowing the path of some handle when going into recursive mode?
You could use resolve() (or whatever we rename it to, the name is ugly)
ah, forgot about the resolve, yea the name is a bit weird, it don't stick and immediately tells you what the fn dose for something... think it's in conflict with the new Promise(resolve =>
how about:
handle.pathRelativeTo(other)handle.relativeTo(other)- or some other...
I had proposed some alternatives names in https://github.com/whatwg/fs/issues/4#issuecomment-1140095707. Let's move the naming discussions to that issue
If this is implemented as parameters to the asynchronous iterator initialization for a directory handle (i.e. parameters to values, keys and entries) presumably the keys returned by keys and entries could somehow return the entire path as well, avoiding the need for a separate path lookup...
So do we need a recursive iterator? IIRC most OS's don't provide such a thing; it's easy enough to build on top of the existing interfaces.
I do think most terminal have a recursive mode when searching/deleting files
Cli commands have different requirements and reasoning for options than API calls.