Skip to content

Instantly share code, notes, and snippets.

@Stray
Created January 8, 2011 18:38
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 Stray/771048 to your computer and use it in GitHub Desktop.
Save Stray/771048 to your computer and use it in GitHub Desktop.
Counts files, lines, words in a folder (by file extension) and then gives you a pure typing time analysis
require 'find'
if ARGV.length != 2
raise ArgumentError.new('Two arguments are required: path, extension')
end
path = ARGV[0]
extension = ARGV[1]
numFiles = 0
lines = 0
words = 0
chars = 0
results = []
Find.find(path) do |f|
if File.file?(f) && File.fnmatch('*.' + extension, f)
File.new(f, "r").each { |line| results << line }
puts "#{f} has"
lines += results.size
results.each do |line|
chars += line.length
words += line.split.length
end
results = []
numFiles += 1
end
end
puts ".#{extension} - #{numFiles} files / #{lines} lines of code / #{words} words of code"
minutes = words/80
hours = minutes/60
days = hours/8
puts "Typing this project should have taken #{minutes} minutes, which is #{hours} hours or #{days} days."
@Stray
Copy link
Author

Stray commented Jan 8, 2011

Run this in your command line like

ruby pathToThisScript/fileMetrics.rb pathToSrcFolder as

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment