From: Logan Capaldo Date: 2006-03-22T07:51:00+09:00 Subject: Re: Find.find and files in cwd On Mar 21, 2006, at 4:38 PM, rtilley wrote: > zdennis wrote: > >> To get only normal files try: >> Dir["*"].delete_if{ |e| not File.file?( e ) } >> To get only directories try: >> Dir["*"].delete_if{ |e| not File.directory?( e ) } >> To get only links try: >> Dir["*"].delete_if{ |e| not File.link?( e ) } >> Zach > > The whole thing seems a bit hackish to me and it still leaves links > to files and links to folders on my Windows test machine. > > I like this: > contents = Dir.entries(Pathname.getwd) > > Better than this: > contents = Dir["#{Dir.getwd}/*"] > > It makes more sense to me and seems more readable. > > I wish that with either approach File.file? would work like this: > > Dir.entries(Pathname.getwd).each do |entry| > if File.file?(entry) > puts entry > end > end > Why not: Dir.entries(Dir.pwd).each do |entry| unless File.directory?(entry) puts entry end end Or Dir.entries(Dir.pwd).reject { |entry| File.directory?(entry) }