Skip to content

Instantly share code, notes, and snippets.

@edsono
Created October 3, 2011 22:37
Show Gist options
  • Save edsono/1260449 to your computer and use it in GitHub Desktop.
Save edsono/1260449 to your computer and use it in GitHub Desktop.
Automove files to right folder...
#!/usr/bin/env ruby
require 'rubygems'
require 'fileutils'
series = {}
Dir['/home/xbmc/series/*'].each do |dirname|
series["^#{File.basename(dirname).downcase}.*"] = dirname
end
Dir['/home/xbmc/download/*'].each do |filename|
basename = File.basename(filename).downcase.gsub("\.", '')
series.keys.each do |regex|
re = Regexp.new(regex)
FileUtils.mv(filename, series[regex]) if re =~ basename
end
FileUtils.mv(filename, '/home/xbmc/movies') if File.exist?(filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment