Last active
December 16, 2015 18:19
-
-
Save tivtag/5476649 to your computer and use it in GitHub Desktop.
Super simple multi-file rename ruby-script for episodic files. ToDo: Add support for seasons and in-between episode identifiers
This file contains 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
folder_path = "E:/path_to_files/" | |
regexp = /(Ep_(?<episode>\d+)_'(?<episode_name>[A-Za-z]+))/ | |
new_filename = "Testname - E<episode> - <episode_name>" | |
accepted = false | |
Dir.glob(folder_path + "/*").sort.each do |file| | |
ext = File.extname(file) | |
old_filename = File.basename(file, File.extname(file)) | |
matches = old_filename.match(regexp) | |
if not matches.nil? then | |
final_filename = new_filename | |
[:episode, :episode_name].each do |sym| | |
final_filename = final_filename.sub("<#{sym}>", matches[sym]) | |
end | |
final_filename = final_filename + ext | |
p "#{old_filename} -> #{final_filename}" | |
if not accepted then | |
p 'Do you want to rename? Y/N?' | |
answer = gets.chomp.downcase | |
if answer == 'y' then | |
accepted = true | |
else | |
return | |
end | |
end | |
final_fullpath = folder_path + "/" + final_filename | |
File.rename(file, final_fullpath) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment