Dictu icon indicating copy to clipboard operation
Dictu copied to clipboard

Add `Path.walk`

Open WillDaSilva opened this issue 3 years ago • 3 comments

I'd be happy if it had the same semantics as Python's os.walk

WillDaSilva avatar Oct 01 '21 14:10 WillDaSilva

This will have to be implemented using a class (e.g. Path.Walker), since Dictu doesn't have stateful functions aka generators. The reason it needs to be stateful is because doing the entire tree traversal before returning limits the usefulness. For instance, if you wanted to search from the root directory and this feature returned a list of every path it would take ages to execute, and the results would use a large amount of memory. Instead we can create an instance of the class given the root of the filesystem tree to be traversed, and have a next method (or some similar name) to get the next [path, dirnames, filenames] triplet. When you call the next method you can optionally provide an updated dirnames list to prune the traversal.

WillDaSilva avatar Oct 01 '21 22:10 WillDaSilva

Rationale makes perfect sense to me, I like it

Jason2605 avatar Oct 01 '21 22:10 Jason2605

446 implements the functionality required within Dictu, however, I'll keep this issue open as a reminder to add it to the stdlib once we work out a viable way of running Dictu code.

Jason2605 avatar Oct 04 '21 21:10 Jason2605