From: Robert Klemme Date: 2004-10-08T18:19:45+09:00 Subject: Re: Sth. wrong with File.file? (or with me) "Michael Weller" schrieb im Newsbeitrag news:41657516.4000602@gutschi.de... > ts wrote: > >>>>>>"M" == Michael Weller writes: > > > > > > M> files = Dir.new(start_dir).to_a[2..-1] #remove . and .. > > M> files.each do |f| > > M> unless File.file? f then > > > > there is only the filename in `f' > > > > Duh. I was almost sure it was me :-)) > > > svg% ls yyy > > aaa > > svg% > > > > svg% ruby -e 'Dir.new("yyy").each {|f| p f}' > > "." > > ".." > > "aaa" > > svg% > > > > you must add `start_dir' for the test File::file? > > > > you can also look at Find::find > > > > svg% ruby -rfind -e 'Find.find("yyy") {|f| p f}' > > "yyy" > > "yyy/aaa" > > svg% > > > > Thanks for your help! > Yes,I think Find was what I was initially searching for. Sth. like > Find::prune would have been my next task... For reasons of completeness: there is also Dir#[] like in 11:11:54 [temp]: ruby -e 'puts Dir["perl/**/*"]' perl/a.wml perl/att.pl perl/bool.pl perl/env-test.pl perl/fun.pl perl/hash.pl perl/here.pl perl/interp.pl perl/method.pl perl/pin.wml perl/repl.pl perl/replace.pl perl/test-2.pl perl/test.pl perl/x perl/x.html perl/x.html~ perl/x.js perl/x.jsf perl/x.jsf~ perl/x.jsp perl/x.jsp~ perl/x~ Another note: if you use File.join() to construct path names, the script will work independent of platform. So the call would look like this then: ruby -e 'puts Dir[File.join("perl", "**", "*")]' Drawback of Dir[] is that the array can get quite huge and you can't stop traversal in between as with find. Also, you can only use file name pattern criteria for selecting the files but not others like the size or modification time. Kind regards robert