@@ -954,21 +954,22 @@ const UV_DIRENT_BLOCK = Cint(7)
954
954
955
955
A type representing a filesystem entry that contains the name of the entry, the directory, and
956
956
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.
959
958
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.
962
967
"""
963
968
struct DirEntry
964
969
dir:: String
965
970
name:: String
966
971
rawtype:: Cint
967
972
end
968
- function DirEntry (path:: String )
969
- dir, name = splitdir (path)
970
- return DirEntry (dir, name, UV_DIRENT_UNKNOWN)
971
- end
972
973
function Base. getproperty (obj:: DirEntry , p:: Symbol )
973
974
if p === :path
974
975
return joinpath (obj. dir, obj. name)
@@ -1009,12 +1010,13 @@ object will be 0 (`UV_DIRENT_UNKNOWN`) and [`isfile`](@ref) etc. will fall back
1009
1010
1010
1011
# Examples
1011
1012
```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)
1018
1020
...
1019
1021
end
1020
1022
end
0 commit comments