Skip to content

Instantly share code, notes, and snippets.

@tumugin
Created November 4, 2015 19:31
Show Gist options
  • Save tumugin/d6acf336340cb81f8ca1 to your computer and use it in GitHub Desktop.
Save tumugin/d6acf336340cb81f8ca1 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'fileutils'
class TermColor
class << self
# 色を解除
def reset ; c 0 ; end
# 各色
def red ; c 31; end
def green ; c 32; end
def yellow ; c 33; end
def blue ; c 34; end
def magenta ; c 35; end
def cyan ; c 36; end
def white ; c 37; end
# カラーシーケンスを出力する
def c(num)
print "\e[#{num.to_s}m"
end
end
end
prognameRegex = /(.*-((.*)((#|♯).*))\.ts|.*-(.*)\.ts)/
basefolder = "Z:/録画フォルダ/"
Dir::glob(basefolder + "*.ts").each {|f|
basename = File::basename(f)
capt = basename.match(prognameRegex).captures
progname = nil
if (capt[2])
progname = capt[2]
elsif (capt[5])
progname = capt[5]
else
puts "No Match:" + basename
end
next if(!progname)
#余計な文字列を削除する
progname.gsub!(/(\[新\])/,"")
progname.rstrip!
progname.gsub!(/^[\s ]+|[\s ]+$/, "")
progname.gsub!("[終]","")
#ゴニョゴニョ
TermColor.cyan
print "Found:"
TermColor.white
puts progname
#下準備としてフォルダを必要に応じて作成する
FileUtils.mkdir_p(basefolder + progname) unless FileTest.exist?(basefolder + progname)
TermColor.green
print "Moving file...."
TermColor.yellow
print basename
TermColor.magenta
#ファイルを移動する
File.rename(f,basefolder + progname + "/" + basename)
puts "....Done!"
TermColor.reset
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment