Created
May 22, 2015 23:14
-
-
Save ouaziz/8bfb13a4a0976191f27d to your computer and use it in GitHub Desktop.
directory size
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
def directory_size(path) | |
path << '/' unless path.end_with?('/') | |
raise RuntimeError, "#{path} is not a directory" unless File.directory?(path) | |
total_size = 0 | |
Dir["#{path}**/*"].each do |f| | |
total_size += File.size(f) if File.file?(f) && File.size?(f) | |
end | |
# size in bytes | |
total_size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment