2009/6/26 David A. Black <dblack / rubypal.com>: > On Fri, 26 Jun 2009, Peter Bailey wrote: > Here's another good use of the string[//] technique: > >>> file = "ehs-g7917741_01.tiff" > > => "ehs-g7917741_01.tiff" >>> >>> file[/[^_]+/] match non-underscore characters > > => "ehs-g7917741" Combining all the good suggestions this is probably what I'd do: files = Dir.glob("L:/infocontiffs/ehs-g7917741/*.tiff") files.each do |f| base = File.basename f root = base[/^([^_]+)_\d+\.tiff$/, 1] if base # rename or whatever else $stderr.puts "Dunno what to do with #{f}" end end The reason I left in the matching of underscores and digits is to be sure that the complete name matches the pattern that we required in order to detect other files that might accidentally have been placed in that directory. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/