Skip to content

Instantly share code, notes, and snippets.

@angristan angristan/rename.rb
Created Dec 1, 2018

Embed
What would you like to do?
Ruby script ro rename all of a dir's files with random names
directory = 'directory/'
new_base_filename_length = 10
Dir.glob(directory + '*').sort.each do |old_filename|
new_base_filename = ('a'..'z').to_a.shuffle[0, new_base_filename_length].join
new_filename = directory + new_base_filename + File.extname(old_filename)
File.rename(old_filename, new_filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.