Repository navigation
Replies: 3 comments 2 replies
|
Hi @N7ghtm4r3, thanks for the idea! Counting and iterating the direct children of a directory already works on every platform with val count = directory.list().size
directory.list().forEach { file -> /* ... */ }What's really missing is a recursive traversal and a directory's total size. I'm open to adding them, and you're welcome to implement them. Before you open a PR, though, let's agree on the API here. Here's what I have in mind: /**
* Lazily walks this directory recursively (depth-first).
* Yields files and subdirectories, but not the starting directory itself.
*/
public fun PlatformFile.walk(maxDepth: Int = Int.MAX_VALUE): Sequence<PlatformFile>
/**
* Returns the total size in bytes of all regular files in this tree.
* For a regular file, returns its own size.
*/
public suspend fun PlatformFile.sizeRecursively(): LongWhich would give: directory.walk().count { it.isRegularFile() } // count files recursively
directory.walk().forEach { file -> /* ... */ } // iterate recursively
directory.sizeRecursively() // total sizeDesign points:
Platform notes:
What's your concrete use case? Does this API cover it, or would you change anything ( |
|
Hi @vinceglb! I just read and I am agree with you about the possible implemention as you said! I have just used that method on The symbolic links I prefer to keep them, specifing that explicit as and option if you agree on it My use case was about on counting files and sum the folder size so what those APIs will cover! If for you is okay I will implement It ASAP? |
Uh oh!
There was an error while loading. Please reload this page.
Hi @vinceglb!
Could be usefult to have some utils for directories like count files, iterating them or size etc?
All reactions