K
Kyle Barbour
Hello everyone,
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:
def getFiles(dir)
pwdFiles = Array.new
Dir.foreach(dir) do |entry|
pwdFiles.push(entry) if File.file?(entry) == true
end
end
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?
Kyle
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:
def getFiles(dir)
pwdFiles = Array.new
Dir.foreach(dir) do |entry|
pwdFiles.push(entry) if File.file?(entry) == true
end
end
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?
Kyle