Problem with the command Dir.entries

Hello, today I used Dir.entries functionnality to list files into a directory, but I seen a problem, this fonction take as well hidden files. How can I prevent that ? Can I had a filter or something like that ?

this should work?

Dir.entries("/my-dir").reject! &.starts_with?('.')
1 Like

This work, thanks you !

But what is this syntax ??? Specially that:

&.starts_with?('.')

https://crystal-lang.org/reference/1.2/syntax_and_semantics/blocks_and_procs.html#short-one-parameter-syntax

1 Like

Oh yes I forgot that. Thanks you !

If all you are trying to remove is just "." and "..", prefer Dir.children instead.

4 Likes

Oh yes perfect, thanks you