diff --git a/base/file.jl b/base/file.jl index 81bca9dd65577..b82665dfdbfba 100644 --- a/base/file.jl +++ b/base/file.jl @@ -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. @@ -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(".") @@ -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) diff --git a/test/file.jl b/test/file.jl index 005c765e08b90..2b10ca7b7950e 100644 --- a/test/file.jl +++ b/test/file.jl @@ -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)