Created
January 30, 2011 22:14
-
-
Save jmcnevin/803324 to your computer and use it in GitHub Desktop.
Sorts a collection of files into folders based on the show name. I use this for TV episodes.
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
#!/usr/bin/env ruby -wKU | |
require 'fileutils' | |
TV_DIR = File.expand_path("~/Movies/TV") | |
EP_PATTERN = /^([a-z\.]+)\.((?:S[\d]+E[\d]+)|(?:[\dx\.]+))\..+\.(?:avi|mkv|mp4|mpg|mpeg)$/i | |
files = Dir[File.join(TV_DIR,'*')] | |
files.each do |f| | |
next unless File.file?(f) | |
base = f.gsub(File.join(TV_DIR,'/'),'') | |
if base =~ EP_PATTERN | |
show_name = $1.gsub('.',' ') | |
show_dir = File.join(TV_DIR,show_name) | |
dest_path = File.join(show_dir,base) | |
FileUtils.mkdir_p(show_dir) | |
FileUtils.mv(f, dest_path) | |
puts "Moved #{f} to #{dest_path}." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment