Skip to content

Instantly share code, notes, and snippets.

@ostinelli
Last active September 5, 2019 19:17
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 ostinelli/751347e91e6f1a4c0af97713536720fb to your computer and use it in GitHub Desktop.
Save ostinelli/751347e91e6f1a4c0af97713536720fb to your computer and use it in GitHub Desktop.
List biggest file size by extension on a directory.
require 'find'
biggest_file_by_ext = {}
Find.find('.') do |path|
next if File.directory?(path)
# get file info
ext = File.extname(path)
next unless ext.length > 0
# get file size
size = File.size(path)
# compare & store in hash
if biggest_file_by_ext.key?(ext)
if size > biggest_file_by_ext[ext]
biggest_file_by_ext[ext] = size
end
else
biggest_file_by_ext[ext] = size
end
end
# print results
biggest_file_by_ext.each do |key, value|
puts "#{key}: #{(value/1024.0/1024.0).round} MB"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment