Skip to content

Instantly share code, notes, and snippets.

@kubido
Created August 18, 2015 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubido/52211316997d8b8e1f7d to your computer and use it in GitHub Desktop.
Save kubido/52211316997d8b8e1f7d to your computer and use it in GitHub Desktop.
rename list youtube downloaded files
keyword = "(Part"
files = Dir.entries('.').select{|x| x.include?(keyword)}
files.each do |file|
wor = file.match(/( \()(.+)(?=.mp4)/)[0]
num = wor.match(/([0-9]+)/)[0]
num = (num.to_i < 10)? "#{0}#{num}" : num
new_name = "#{num}. #{file.gsub(wor, '')}"
File.rename(file, "#{Dir.pwd}/#{new_name}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment