Skip to content

Commit d61f7c1

Browse files
remove DirEntry path constructor. Improve docs
1 parent 3326ff3 commit d61f7c1

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

base/file.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -954,21 +954,22 @@ const UV_DIRENT_BLOCK = Cint(7)
954954
955955
A type representing a filesystem entry that contains the name of the entry, the directory, and
956956
the raw type of the entry. The full path of the entry can be obtained lazily by accessing the
957-
`path` field. The type of the entry can be checked for by calling [`isfile`](@ref), [`isdir`](@ref),
958-
[`islink`](@ref), [`isfifo`](@ref), [`issocket`](@ref), [`ischardev`](@ref), and [`isblockdev`](@ref).
957+
`path` field.
959958
960-
If constructed manually via `DirEntry(path::String)`, the type of the entry is unknown and so `isfile`
961-
etc. will fall back to a `stat` call.
959+
Public fields:
960+
- `dir::String`: The directory containing the entry.
961+
- `name::String`: The name of the entry.
962+
- `path::String`: The full path of the entry, lazily constructed from `dir` and `name`. Also accessible via `joinpath(entry)`.
963+
964+
The type of the entry can be checked for by calling [`isfile`](@ref), [`isdir`](@ref),
965+
[`islink`](@ref), [`isfifo`](@ref), [`issocket`](@ref), [`ischardev`](@ref), and [`isblockdev`](@ref)
966+
on the entry object.
962967
"""
963968
struct DirEntry
964969
dir::String
965970
name::String
966971
rawtype::Cint
967972
end
968-
function DirEntry(path::String)
969-
dir, name = splitdir(path)
970-
return DirEntry(dir, name, UV_DIRENT_UNKNOWN)
971-
end
972973
function Base.getproperty(obj::DirEntry, p::Symbol)
973974
if p === :path
974975
return joinpath(obj.dir, obj.name)
@@ -1009,12 +1010,13 @@ object will be 0 (`UV_DIRENT_UNKNOWN`) and [`isfile`](@ref) etc. will fall back
10091010
10101011
# Examples
10111012
```julia
1012-
for obj in readdir(DirEntry, ".")
1013-
isfile(obj) && println("\$(obj.name) is a file with path \$(obj.path)")
1014-
end
1015-
for obj in readdir(DirEntry(path))
1016-
isdir(obj) || continue
1017-
for obj2 in readdir(obj)
1013+
for entry in readdir(DirEntry, ".")
1014+
if isfile(entry)
1015+
println("\$(entry.name) is a file with path \$(entry.path)")
1016+
continue
1017+
end
1018+
isdir(entry) || continue
1019+
for entry2 in readdir(entry)
10181020
...
10191021
end
10201022
end

test/file.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ end
3131
@test isdir("does/not/exist") == false
3232
@test_throws Base.IOError readdir("does/not/exist")
3333
@test_throws Base.IOError readdir(DirEntry, "does/not/exist")
34-
@test_throws Base.IOError readdir(DirEntry("does/not/exist"))
3534

3635
mktempdir() do dir
3736
touch(joinpath(dir, "afile.txt"))
3837
mkdir(joinpath(dir, "adir"))
3938
touch(joinpath(dir, "adir", "bfile.txt"))
4039
@test length(readdir(dir)) == 2
4140
@test readdir(dir) == map(e->e.name, readdir(DirEntry, dir))
42-
@test readdir(DirEntry, dir) == readdir(DirEntry(dir))
4341
for p in readdir(dir, join=true)
4442
if isdir(p)
4543
@test only(readdir(p)) == "bfile.txt"

0 commit comments

Comments
 (0)