Wednesday, December 01, 2010

Ruby saved the day.

require 'FileUtils'
Dir.glob("*.xml").each do f
if File.read(f) =~ /searchstring/ then
FileUtils.mv(f, "c:/destination_directory/" + f)
end
end

This code cycles through the contents of every xml file in the current directory looking for the search string then moves the files that have the string to another directory.

No comments: