Skip to content

Add scandir#62164

Open
IanButterworth wants to merge 2 commits into
JuliaLang:masterfrom
IanButterworth:ib/scandir
Open

Add scandir#62164
IanButterworth wants to merge 2 commits into
JuliaLang:masterfrom
IanButterworth:ib/scandir

Conversation

@IanButterworth

@IanButterworth IanButterworth commented Jun 18, 2026

Copy link
Copy Markdown
Member

Adds scandir, a lazy version of readdir

Split out of JuliaLang#55358 at triage's request, stacked on the
`DirEntry` / `readdir(dir, DirEntry)` work.

`scandir(dir)` returns a stateful, single-pass `DirEntryIterator` that streams
filename `String`s one entry at a time via `uv_fs_opendir` / `uv_fs_readdir`,
without first materializing the full listing. This is useful for very large
directories or when iteration is short-circuited (e.g. `break` or
`Iterators.take`). `scandir(dir, DirEntry)` yields `DirEntry` objects instead,
and a do-block form `scandir(f, dir[, DirEntry])` releases the underlying
directory handle as soon as `f` returns; otherwise cleanup happens at
end-of-iteration, on `close`, or via a finalizer.

The element-type selector uses a trailing type argument to match
`readdir(dir, DirEntry)`. New runtime helpers `jl_uv_fs_opendir`,
`jl_uv_fs_readdir`, and `jl_uv_fs_closedir` wrap the libuv directory API and
hide the `uv_dir_t` layout from Julia.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@IanButterworth IanButterworth marked this pull request as ready for review June 19, 2026 02:37
Comment thread NEWS.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant