Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pwd() as the default directory to walk in walkdir #55550

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ function _readdir(dir::AbstractString; return_objects::Bool=false, join::Bool=fa
end

"""
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)
walkdir(dir = pwd(); topdown=true, follow_symlinks=false, onerror=throw)

Return an iterator that walks the directory tree of a directory.

Expand All @@ -1107,6 +1107,9 @@ resume where the last left off, like [`Iterators.Stateful`](@ref).

See also: [`readdir`](@ref).

!!! compat "Julia 1.12"
`pwd()` as the default directory was added in Julia 1.12.

# Examples
```julia
for (path, dirs, files) in walkdir(".")
Expand Down Expand Up @@ -1136,7 +1139,7 @@ julia> (path, dirs, files) = first(itr)
("my/test/dir", String[], String[])
```
"""
function walkdir(path; topdown=true, follow_symlinks=false, onerror=throw)
function walkdir(path = pwd(); topdown=true, follow_symlinks=false, onerror=throw)
function _walkdir(chnl, path)
tryf(f, p) = try
f(p)
Expand Down
7 changes: 7 additions & 0 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,13 @@ cd(dirwalk) do
@test dirs == []
@test files == ["foo"]
end

# pwd() as default directory
for ((r1, d1, f1), (r2, d2, f2)) in zip(walkdir(), walkdir(pwd()))
@test r1 == r2
@test d1 == d2
@test f1 == f2
end
end
rm(dirwalk, recursive=true)

Expand Down