fs icon indicating copy to clipboard operation
fs copied to clipboard

Convenience method for recursive directory iteration

Open a-sully opened this issue 3 years ago • 8 comments

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)
}

a-sully avatar Mar 08 '22 20:03 a-sully

question: How would we deal with knowing the path of some handle when going into recursive mode?

jimmywarting avatar Jun 28 '22 20:06 jimmywarting

You could use resolve() (or whatever we rename it to, the name is ugly)

jesup avatar Jun 29 '22 13:06 jesup

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...

jimmywarting avatar Jun 29 '22 13:06 jimmywarting

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

a-sully avatar Jun 29 '22 14:06 a-sully

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...

mkruisselbrink avatar Jun 29 '22 16:06 mkruisselbrink

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.

jesup avatar Jul 01 '22 02:07 jesup

I do think most terminal have a recursive mode when searching/deleting files

jimmywarting avatar Jul 01 '22 23:07 jimmywarting

Cli commands have different requirements and reasoning for options than API calls.

jesup avatar Jul 10 '22 03:07 jesup