require "fileutils" class AvidMover Bin = Struct.new(:type, :genre, :filename) def initialize(project_path) @project_path = project_path end def move_bins @bin_names = Dir.glob("#{@project_path}*.avb") @bin_names.each do |name| source = name split_name = name.split("/").last.split("-") bin = Bin.new(split_name[0], split_name[1], split_name[2]) dest_path = "#{@project_path}#{bin.type}/#{bin.genre}/" dest = "#{dest_path}#{bin.filename}" begin unless Dir.exist? dest_path FileUtils.mkdir_p dest_path end FileUtils.mv source, dest puts "Moving to #{dest}" rescue puts "Can't move to #{dest}" next end end end end