From: Kyle Barbour on 2 Aug 2010 08:28
I'm new to Ruby, so I'm most likely making an elementary mistake.
However, searching Google didn't help me find my answer, and after
mucking around with irb I still haven't figured it out.
I wrote a method that was intended to take all of the files in a given
directory and put them into an array. Here's the code I wrote:
pwdFiles = Array.new
Dir.foreach(dir) do |entry|
pwdFiles.push(entry) if File.file?(entry) == true
This works fine when called on the working directory --- that is,
getFiles(Dir.pwd). However, when I call it on a subdirectory --- for
example, getFiles("doc") --- it only returns one file. I tested to
make sure that the files being ignored in the subdirectory actually
gave "true" when tested with File.file?(entry), which they do.
Anyone know what I'm doing wrong?