Skip to content

Instantly share code, notes, and snippets.

@tcdowney
Created May 21, 2019 01:55
Show Gist options
  • Save tcdowney/c429b56470cbb5d8f40a18e7a2983024 to your computer and use it in GitHub Desktop.
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
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