Iterate through every file in one directory

How do I write a loop in ruby so that I can execute a block of code on each file?

I’m new to ruby, and I’ve concluded that the way to do this is a do each loop.
The ruby file will be executed from a different directory than the directory I want to loop through.

I’ve tried the Dir.foreach and I couldn’t get it to work.

8 Answers
8

Leave a Comment