you open up an I/O stream with dir : IO.popen File Directory Ruby


# read the lines one by one, as with other forms of I/O streams, and close the stream

ls = IO.popen("dir", "r")
while line = ls.gets
  puts line
end
ls.close