From: Brian Candler Date: 2010-08-11T19:52:46+09:00 Subject: Re: Formatting directory listings simonh wrote: > By the way, I know that: > > films = Dir['**/*.avi'] > > will give me an array with the full pathnames. I'm after help with > extracting the parent directory name. (1) You can strip it textually path = "foo/bar/baz.avi" basename = path.sub(/^.*\//,'') (2) You can use the Pathname class require 'pathname' path = "foo/bar/baz.avi" basename = Pathname.new(path).basename.to_s (3) You can use Dir.foreach in a specific directory (but that won't traverse arbitrary subdirectories like **/* does) Dir.foreach("/etc") { |b| puts b } -- Posted via http://www.ruby-forum.com/.