Created
May 21, 2019 01:55
-
-
Save tcdowney/c429b56470cbb5d8f40a18e7a2983024 to your computer and use it in GitHub Desktop.
Hacky rename of Intro to Graduate Algorithms videos to get sorted correctly on Kindle Fire
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
leading_digit_regex = /\d+\s+/ | |
path = '/Users/tcdowney/Downloads/ga-vids' | |
Dir.glob("#{path}/*.mp4") do |mp4_file| | |
filename = File.basename(mp4_file, File.extname(mp4_file)) | |
leading_digits = filename.match(leading_digit_regex)[0].to_i | |
padded_digits = sprintf('%03d', leading_digits) | |
padded_filename = filename.gsub(leading_digits.to_s, padded_digits) | |
#puts padded_filename + File.extname(mp4_file) | |
File.rename(mp4_file, padded_filename + File.extname(mp4_file)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment