Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

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.

Ruby in Windows Path syntax

basedir = "c:/test"

Notice the / and not \

duh
*smacks head*