From: "Peña, Botp" Date: 2009-02-05T17:05:44+09:00 Subject: Re: Return actual files only not directories, using Pathname.. From: Brian Wallace [mailto:draygen80@gmail.com] # I'd like to use Pathname, Pathname is a very nice façade for a lot of file things ;) # to return only actual filenames in the array... # But I rather like Pathname ... Since I can use it like this: # a = Pathname("/Path") # b = a.children # puts b[1] #==> "/Path/file1.txt" # b[1].read #==> "This is data in a file named file1.txt" # puts b[2] #==> "/Path/file2.txt" # ..... try passing a boolean arg to children, eg b = a.children(false) # Does anyone have any tips on how I could use Pathname to # return files only, and not directories? *nixism, they're simply all files, you'll have ask more. try #file? or #directory?, eg b[1].file? b[1].directory? warning: be careful when mixing result of #children(false) with other pathname methods. on your case, to get only the files (non-dir ie), i'd probably just do, b = a.children.select do |path| path.file? end and to get a list of the names (as strings ie) b.map do |path| path.basename.to_s end and if you want to get a separate list of files and dirs, try partition, eg files, dirs = a.children.partition do |path| path.file? end