@@ -671,27 +671,70 @@ struct uv_dirent_t
671
671
end
672
672
673
673
"""
674
- readdir(dir::AbstractString="." ) -> Vector{String}
674
+ readdir(dir::AbstractString=pwd(); join::Bool=true ) -> Vector{String}
675
675
676
- Return the files and directories in the directory `dir` (or the current working directory if not given).
676
+ Return the names in the directory `dir` or the current working directory if not
677
+ given. When `join` is false, `readdir` returns just the names in the directory
678
+ as is; when `join` is true, it returns `joinpath(dir, name)` for each `name` so
679
+ that the returned strings are full paths. If you want to get absolute paths
680
+ back, call `readdir` with an absolute directory path and `join` set to true.
677
681
678
682
# Examples
679
683
```julia-repl
680
- julia> readdir("/home/JuliaUser/Projects/julia")
681
- 34-element Array{String,1}:
682
- ".circleci"
683
- ".freebsdci.sh"
684
+ julia> cd("/home/JuliaUser/dev/julia")
685
+
686
+ julia> readdir()
687
+ 30-element Array{String,1}:
688
+ ".appveyor.yml"
684
689
".git"
685
690
".gitattributes"
686
- ".github"
687
691
⋮
688
- "test"
689
692
"ui"
690
693
"usr"
691
694
"usr-staging"
695
+
696
+ julia> readdir(join=true)
697
+ 30-element Array{String,1}:
698
+ "/home/JuliaUser/dev/julia/.appveyor.yml"
699
+ "/home/JuliaUser/dev/julia/.git"
700
+ "/home/JuliaUser/dev/julia/.gitattributes"
701
+ ⋮
702
+ "/home/JuliaUser/dev/julia/ui"
703
+ "/home/JuliaUser/dev/julia/usr"
704
+ "/home/JuliaUser/dev/julia/usr-staging"
705
+
706
+ julia> readdir("base")
707
+ 145-element Array{String,1}:
708
+ ".gitignore"
709
+ "Base.jl"
710
+ "Enums.jl"
711
+ ⋮
712
+ "version_git.sh"
713
+ "views.jl"
714
+ "weakkeydict.jl"
715
+
716
+ julia> readdir("base", join=true)
717
+ 145-element Array{String,1}:
718
+ "base/.gitignore"
719
+ "base/Base.jl"
720
+ "base/Enums.jl"
721
+ ⋮
722
+ "base/version_git.sh"
723
+ "base/views.jl"
724
+ "base/weakkeydict.jl"```
725
+
726
+ julia> readdir(abspath("base"), join=true)
727
+ 145-element Array{String,1}:
728
+ "/home/JuliaUser/dev/julia/base/.gitignore"
729
+ "/home/JuliaUser/dev/julia/base/Base.jl"
730
+ "/home/JuliaUser/dev/julia/base/Enums.jl"
731
+ ⋮
732
+ "/home/JuliaUser/dev/julia/base/version_git.sh"
733
+ "/home/JuliaUser/dev/julia/base/views.jl"
734
+ "/home/JuliaUser/dev/julia/base/weakkeydict.jl"
692
735
```
693
736
"""
694
- function readdir (dir:: AbstractString )
737
+ function readdir (dir:: AbstractString = pwd (); join :: Bool = false )
695
738
# Allocate space for uv_fs_t struct
696
739
uv_readdir_req = zeros (UInt8, ccall (:jl_sizeof_uv_fs_t , Int32, ()))
697
740
@@ -704,7 +747,8 @@ function readdir(dir::AbstractString)
704
747
entries = String[]
705
748
ent = Ref {uv_dirent_t} ()
706
749
while Base. UV_EOF != ccall (:uv_fs_scandir_next , Cint, (Ptr{Cvoid}, Ptr{uv_dirent_t}), uv_readdir_req, ent)
707
- push! (entries, unsafe_string (ent[]. name))
750
+ name = unsafe_string (ent[]. name)
751
+ push! (entries, join ? joinpath (dir, name) : name)
708
752
end
709
753
710
754
# Clean up the request string
@@ -713,8 +757,6 @@ function readdir(dir::AbstractString)
713
757
return entries
714
758
end
715
759
716
- readdir () = readdir (" ." )
717
-
718
760
"""
719
761
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)
720
762
0 commit comments