Skip to content

Instantly share code, notes, and snippets.

@Fedcomp
Created October 21, 2018 18:14
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 Fedcomp/84f87ff19dc026a49aacda20e034d44e to your computer and use it in GitHub Desktop.
Save Fedcomp/84f87ff19dc026a49aacda20e034d44e to your computer and use it in GitHub Desktop.
Hash all files in directory
require 'pathname'
require 'digest'
Pathname.new(Dir.pwd).children.select(&:file?).each do |file|
next if file.basename.to_s.start_with?('hashed_') || file.extname == '.rb'
file_md5 = Digest::MD5.file(file).hexdigest
old_name = file.basename
new_name = "hashed_#{file_md5}_#{old_name}"
puts "#{old_name} -> #{new_name}"
File.rename old_name, new_name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment