Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify Folders in Sub-Folder

Tags:

julia

I have a working directory with the following content

readdir()

6-element Vector{String}:
 "Manifest.toml"
 "Project.toml"
 "Report"
 "main.jl"
 "src"
 "test.jl"

I can identify folders here:

filter(isdir, readdir())

2-element Vector{String}:
 "Report"
 "src"

And I can show the content of the sub-folder Report:

readdir("Report/")

3-element Vector{String}:
 "jl_ACKKIu"
 "jl_zfa8Ys"
 "test.pdf"

So, why can I not identify folders in the sub-folder?

filter(isdir, readdir("Report/"))

String[]
like image 346
Georgery Avatar asked Apr 18 '26 11:04

Georgery


1 Answers

readdir contains paths relative to the input directory and isdir then interprets these paths as relative to the current working directory (see pwd).

Since Julia 1.4 you can pass join=true as a keyword argument to readdir, such that the returned paths are joined with the input path:

shell> tree .
.
├── DirectoryB
│   ├── DirectoryC
│   └── FileB
└── FileA

2 directories, 2 files

julia> readdir("DirectoryB")
2-element Vector{String}:
 "DirectoryC"
 "FileB"

julia> readdir("DirectoryB"; join=true)
2-element Vector{String}:
 "DirectoryB/DirectoryC"
 "DirectoryB/FileB"

julia> filter(isdir, ans)
1-element Vector{String}:
 "DirectoryB/DirectoryC"
like image 99
fredrikekre Avatar answered Apr 22 '26 14:04

fredrikekre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!