Get all dirs and files recursively

Hello, I have a question because it look like I have to implement it. But just in case, I will ask my question: is there anyway with the standard crystal functions to list all dirs and files recursively in a given dir ?

I mean, if the function see my given dir contain an another dir, it return it content as well recursively. Because I need to have an array of all files and dirs in a given dir

1 Like

You can use Dir.glob("path/to/folder/**/*") to collect all file and folder paths in a directory tree.


As an extra mention, all those (basic) question, user can search it on crystal api, if you consider the api explanation is not clear enough, you can always search same keyword from ruby std-lib, there are more detailed examples. e.g. for the answer of this question, check this link

1 Like

Though admittedly for this specific question it’s not very obvious how to do that just from the API docs. The documentation for glob is very sparse and misses examples.
So of course you can search for yourself or look how to do it in Ruby and see if it translates.

But I think it’s good to ask here because that points out shortcomings in the documentation.


Yeah I agree the documentation misses examples for that. Thank you for your help