From: Joel VanderWerf Date: 2006-01-29T03:42:04+09:00 Subject: Re: working with file types and directories John Maclean wrote: > OK, next step... > I can now run tests on files within directories. How can I achieve > something like the following? > > puts "files have been checked" if Dir.foreach(".") {|x| puts > FileTest.writable?(x) } == "true" > > #at the moment I get this:- > irb(main):022:0> puts "files have been checked" if Dir.foreach(".") > {|x| puts FileTest.writable?(x) } == "true" true > true > true > true > true > true > > #but *not* the desired string "files have been checked" Comparing the return value with the string "true" won't work because you are outputting each writeable? result to stdout, and anyway that output needs to be and-ed to test if all of the files are writable. You do want the "files have been checked" output if all files are writable, right? Here's one way: puts "files have been checked" if Dir.new(".").all? {|x| FileTest.writable?(x) } -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407