Skip to content

Instantly share code, notes, and snippets.

@sandrods
Created April 18, 2011 23:00
Show Gist options
  • Select an option

  • Save sandrods/926459 to your computer and use it in GitHub Desktop.

Select an option

Save sandrods/926459 to your computer and use it in GitHub Desktop.
file renamer
# Dir["*.{srt}"].each do |f|
#
# replace = "S4"
# por = "S04"
#
# File.rename(f, f.gsub(replace, por))
#
# end
# Dir["*.{srt}"].each do |f|
#
# f =~ /S(\d?\d)E(\d\d)(.*).HDTV(.*).srt/
# por = "Six.Feet.Under.S#{$1}E#{$2}.HDTV#{$4}.srt"
#
# puts f
# puts por
#
#
# File.rename(f, por)
#
# end
avis = Dir["*.{avi}"]
Dir["*.{srt}"].each do |f|
f =~ /(Six.Feet.Under.S(\d?\d)E(\d\d)(.*)).srt/
avi_name = "#{$1}.avi"
#rgx = %r(S#{$2}E#{$3})
rgx = %r(#{$2.to_i}x#{$3})
avi = avis.detect { |s| s =~ rgx }
puts f
puts avi_name
puts avi
puts
File.rename(avi, avi_name) if avi
end
#~ Dir["*.{avi}"].each do |f|
#~ n = File.basename(f, ".avi")
#~ origem = n.downcase+".srt"
#~ destino = n+".srt"
#~ File.rename(origem, destino) if FileTest.exists?(origem)
#~ puts f
#~ end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment