diff --git a/NEWS.md b/NEWS.md index 0746273f41d603..56a2ffb8d539d6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -33,8 +33,6 @@ New library functions --------------------- * `logrange(start, stop; length)` makes a range of constant ratio, instead of constant step ([#39071]) -* `readdirx` for returning directory contents along with the type of the entries in a vector of new `DirEntry` - objects ([#53377]) New library features -------------------- diff --git a/base/exports.jl b/base/exports.jl index 64b1e133039ca0..ac735bb25d0fe9 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -866,7 +866,6 @@ export readbytes!, readchomp, readdir, - readdirx, readline, readlines, readuntil, diff --git a/base/file.jl b/base/file.jl index 4a669cbad3cd55..f2e1aedb893763 100644 --- a/base/file.jl +++ b/base/file.jl @@ -19,7 +19,6 @@ export rename, readlink, readdir, - readdirx, rm, samefile, sendfile, @@ -979,13 +978,13 @@ ischardev(obj::DirEntry) = (isunknown(obj) || islink(obj)) ? ischardev(obj.path isblockdev(obj::DirEntry) = (isunknown(obj) || islink(obj)) ? isblockdev(obj.path) : obj.rawtype == UV_DIRENT_BLOCK """ - readdirx(dir::AbstractString=pwd(); sort::Bool = true) -> Vector{DirEntry} + _readdirx(dir::AbstractString=pwd(); sort::Bool = true) -> Vector{DirEntry} Return a vector of [`DirEntry`](@ref) objects representing the contents of the directory `dir`, or the current working directory if not given. If `sort` is true, the returned vector is sorted by name. -Unlike [`readdir`](@ref), `readdirx` returns [`DirEntry`](@ref) objects, which contain the name of the +Unlike [`readdir`](@ref), `_readdirx` returns [`DirEntry`](@ref) objects, which contain the name of the file, the directory it is in, and the type of the file which is determined during the directory scan. This means that calls to [`isfile`](@ref), [`isdir`](@ref), [`islink`](@ref), [`isfifo`](@ref), [`issocket`](@ref), [`ischardev`](@ref), and [`isblockdev`](@ref) can be made on the @@ -994,12 +993,12 @@ cannot be determined without a stat call. In these cases the `rawtype` field of object will be 0 (`UV_DIRENT_UNKNOWN`) and [`isfile`](@ref) etc. will fall back to a `stat` call. ```julia -for obj in readdirx() +for obj in _readdirx() isfile(obj) && println("$(obj.name) is a file with path $(obj.path)") end ``` """ -readdirx(dir::AbstractString=pwd(); sort::Bool=true) = _readdir(dir; return_objects=true, sort)::Vector{DirEntry} +_readdirx(dir::AbstractString=pwd(); sort::Bool=true) = _readdir(dir; return_objects=true, sort)::Vector{DirEntry} function _readdir(dir::AbstractString; return_objects::Bool=false, join::Bool=false, sort::Bool=true) # Allocate space for uv_fs_t struct diff --git a/doc/src/base/file.md b/doc/src/base/file.md index 075a694dff31f1..81cf8aa059b9b2 100644 --- a/doc/src/base/file.md +++ b/doc/src/base/file.md @@ -7,7 +7,6 @@ Base.Filesystem.pwd Base.Filesystem.cd(::AbstractString) Base.Filesystem.cd(::Function) Base.Filesystem.readdir -Base.Filesystem.readdirx Base.Filesystem.DirEntry Base.Filesystem.walkdir Base.Filesystem.mkdir diff --git a/test/file.jl b/test/file.jl index b8c1983e931ca1..c7fe3e88fece9f 100644 --- a/test/file.jl +++ b/test/file.jl @@ -31,7 +31,7 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER symlink(subdir, dirlink) @test stat(dirlink) == stat(subdir) @test readdir(dirlink) == readdir(subdir) - @test readdirx(dirlink) == readdirx(subdir) + @test Base.Filesystem._readdirx(dirlink) == Base.Filesystem._readdirx(subdir) # relative link relsubdirlink = joinpath(subdir, "rel_subdirlink") @@ -39,7 +39,7 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER symlink(reldir, relsubdirlink) @test stat(relsubdirlink) == stat(subdir2) @test readdir(relsubdirlink) == readdir(subdir2) - @test readdirx(relsubdirlink) == readdirx(subdir2) + @test Base.Filesystem._readdirx(relsubdirlink) == Base.Filesystem._readdirx(subdir2) # creation of symlink to directory that does not yet exist new_dir = joinpath(subdir, "new_dir") @@ -58,7 +58,7 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER mkdir(new_dir) touch(foo_file) @test readdir(new_dir) == readdir(nedlink) - @test readdirx(new_dir) == readdirx(nedlink) + @test Base.Filesystem._readdirx(new_dir) == Base.Filesystem._readdirx(nedlink) rm(foo_file) rm(new_dir) @@ -1444,10 +1444,10 @@ rm(dirwalk, recursive=true) touch(randstring()) end @test issorted(readdir()) - @test issorted(readdirx()) - @test map(o->o.name, readdirx()) == readdir() - @test map(o->o.path, readdirx()) == readdir(join=true) - @test count(isfile, readdir(join=true)) == count(isfile, readdirx()) + @test issorted(_readdirx()) + @test map(o->o.name, Base.Filesystem._readdirx()) == readdir() + @test map(o->o.path, Base.Filesystem._readdirx()) == readdir(join=true) + @test count(isfile, readdir(join=true)) == count(isfile, Base.Filesystem._readdirx()) end end end