From: Robert Klemme Date: 2012-03-18T21:47:49+09:00 Subject: Re: Find from array and move Chas Conquest wrote in post #1051998: > I'm needing to cull 900 files from about 3500 files in 100 different > directories. > > I have an array with the 900 files ie. ["2100_01", "2102_05", "2105_04", > "etc....."] That would be an array of fileNAMES. > The files in question are named like so...."2100_01.aif" > > Based on the array, I need to match/find these files from within the > 100 directories and copy/move each one into a new single directory. Pathname has quite a few nice tools for this. Something along these lines could work: require 'set' require 'pathname' array = ... # as described source = ... # source directory path target = ... # target directory path index = array.to_set # more efficient lookup tgt = Pathname(target) abort "Not a directory: #{tgt}" unless tgt.directory? Pathname(source).find do |f| f.file? and index.include? f.basename('.aif') and f.rename(tgt + f.basename) end Kind regards robert -- Posted via http://www.ruby-forum.com/.