Skip to content

Commit

Permalink
Use pwd() as the default directory to walk in walkdir (#55550)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Oct 24, 2024
1 parent bc66047 commit dc60727
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,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 @@ -1117,6 +1117,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 @@ -1146,7 +1149,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 @@ -1728,6 +1728,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

0 comments on commit dc60727

Please sign in to comment.