I want to get all file names from a folder using Ruby.
You posted this answer 15 minutes ago. You posted the question 15 minutes ago. Are you experiencing an interesting mental event? Did the right half of your brain not know the answer as your hands were typing the question? Did the part of your mind that did know the answer take over immediately after you finished typing the question? (This seems to be a pattern with your Ruby questions: post question; answer own question right after.)
Telemachus
2009-11-18 12:52:05
Looks like he's using SO to document the answers to questions he's just asked. A sort of memo, I suppose. Can't see much wrong with that - after all, even though this one is a little incomplete (`Dir#glob` could have perhaps been mentioned, for instance) there's nothing to prevent someone else from posting a Really Good Answer.'course, I'm mostly a "glass half full" sort of a guy...
Mike Woodhouse
2009-11-18 13:05:58
@Mike: In the grand scheme of things, it's probably not a big deal. And as you say if the questions and answers were good, it could be a plus overall for the site. But here both question and answer are so minimal that it doesn't seem especially useful.
Telemachus
2009-11-18 13:11:53
@Telemachus I use `Dir` rarely, and every time I need it I have to read documentation. I have posted my question and answer here so I could find it later, and maybe even help someone with the same question. I think I have heard at SO podcast that there is nothing wrong with such behavior. If you have a better answer, please post it. I have posted what I know, I am not a Ruby ninja. I regularly accept answers with the most votes.
Željko Filipin
2009-11-19 10:42:01
+2
A:
You also have the shortcut option of
Dir["/path/to/search/*"]
and if you want to find all Ruby files in any folder or sub-folder:
Dir["/path/to/search/**/*.rb"]
Ian
2009-11-18 12:44:09