Last active
September 5, 2019 19:17
-
-
Save ostinelli/751347e91e6f1a4c0af97713536720fb to your computer and use it in GitHub Desktop.
List biggest file size by extension on a directory.
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
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