Skip to content

Instantly share code, notes, and snippets.



Created Jan 3, 2020
What would you like to do?
[Movey] A simple ruby script to move a movie file to the correct location. #ruby
require 'colorize'
require 'fileutils'
require 'highline/import'
require 'optparse'
exts = ['.avi', '.m4v', '.mkv', '.mp4', '.srt', '.sub']
# Loop through each ARGV
ARGV.each do |arg|
arg = File.basename(arg)
# If arg is directory
# Loop through files in arg dir
Dir.foreach(arg) do |filename|
next if filename == '.' or filename == '..'
path = "#{arg}/#{filename}"
ext = File.extname(filename)
# If not a stoopid mac metadata file and is an acceptable filetype, continue
if filename[0..1] != '._' and exts.include?(ext)
if ['.srt', '.sub'].include? ext
ext = ".en.#{ext}"
newname = "#{arg}/#{filename}"
if path != newname
puts "< #{path}".colorize(:blue)
File.rename(path, newname)
puts "> #{newname}".colorize(:green)
puts "- #{path}".colorize(:red)
end # if exts.include?
end # Dir.foreach
target = "/netshare/videos/movies/#{arg}"
# Check if target directory exists
if File.exists?(target)
# If exists, ask if we want to overwright
a = ''
until %w[y n].include?(a)
a = ask("Target #{target} already exists. Do you want to overwrite it? [Y/n] ") { |q| q.limit = 1; = :downcase }
a = 'y' if a.length == 0
next if a != 'y'
end # if File.exists?
# Move dir to new home, "/netshare/videos/movies/")
end # if
end # ARGV.each
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.