Skip to content

Commit dc60727

Browse files
authored
Use pwd() as the default directory to walk in walkdir (#55550)
1 parent bc66047 commit dc60727

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

base/file.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ function _readdir(dir::AbstractString; return_objects::Bool=false, join::Bool=fa
11001100
end
11011101

11021102
"""
1103-
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)
1103+
walkdir(dir = pwd(); topdown=true, follow_symlinks=false, onerror=throw)
11041104
11051105
Return an iterator that walks the directory tree of a directory.
11061106
@@ -1117,6 +1117,9 @@ resume where the last left off, like [`Iterators.Stateful`](@ref).
11171117
11181118
See also: [`readdir`](@ref).
11191119
1120+
!!! compat "Julia 1.12"
1121+
`pwd()` as the default directory was added in Julia 1.12.
1122+
11201123
# Examples
11211124
```julia
11221125
for (path, dirs, files) in walkdir(".")
@@ -1146,7 +1149,7 @@ julia> (path, dirs, files) = first(itr)
11461149
("my/test/dir", String[], String[])
11471150
```
11481151
"""
1149-
function walkdir(path; topdown=true, follow_symlinks=false, onerror=throw)
1152+
function walkdir(path = pwd(); topdown=true, follow_symlinks=false, onerror=throw)
11501153
function _walkdir(chnl, path)
11511154
tryf(f, p) = try
11521155
f(p)

test/file.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,13 @@ cd(dirwalk) do
17281728
@test dirs == []
17291729
@test files == ["foo"]
17301730
end
1731+
1732+
# pwd() as default directory
1733+
for ((r1, d1, f1), (r2, d2, f2)) in zip(walkdir(), walkdir(pwd()))
1734+
@test r1 == r2
1735+
@test d1 == d2
1736+
@test f1 == f2
1737+
end
17311738
end
17321739
rm(dirwalk, recursive=true)
17331740

0 commit comments

Comments
 (0)