Last active
June 10, 2016 16:22
-
-
Save nycdavid/423312c79f7530401ccd to your computer and use it in GitHub Desktop.
AvidMover class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment