Skip to content

Instantly share code, notes, and snippets.

@ouaziz
Created May 22, 2015 23:14
Show Gist options
  • Save ouaziz/8bfb13a4a0976191f27d to your computer and use it in GitHub Desktop.
Save ouaziz/8bfb13a4a0976191f27d to your computer and use it in GitHub Desktop.
directory size
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