Skip to content

Instantly share code, notes, and snippets.

@destroytoday
Created November 25, 2010 10:24
Show Gist options
  • Save destroytoday/715174 to your computer and use it in GitHub Desktop.
Save destroytoday/715174 to your computer and use it in GitHub Desktop.
Prints the number of files and lines of code inside the given path with the given extension
require 'find'
if ARGV.length != 2
raise ArgumentError.new('Two arguments are required: path, extension')
end
path = ARGV[0]
extension = ARGV[1]
numFiles = 0
numLines = 0
Find.find(path) do |f|
if File.file?(f) && File.fnmatch('*.' + extension, f)
numFiles += 1
numLines += File.new(f, 'r').readlines.length
end
end
puts ".#{extension} - #{numFiles} files / #{numLines} lines of code"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment