Skip to content

Instantly share code, notes, and snippets.

@seanchas116
Created April 28, 2013 15:05
Show Gist options
  • Save seanchas116/5477131 to your computer and use it in GitHub Desktop.
Save seanchas116/5477131 to your computer and use it in GitHub Desktop.
A Ruby script that just counts the number of lines in a given directory
require 'pathname'
def count_lines(pathname)
count = 0
pathname.each_child do |child|
if child.directory?
count = count + count_lines(child)
elsif child.file?
count = count + %x{wc -l \"#{child.to_s}\"}.split.first.to_i
end
end
count
end
if ARGV.length != 1
puts "Error: invalid arguments"
exit()
end
pathname = Pathname.new(ARGV[0])
if !pathname.exist? || !pathname.directory?
puts "Error: directory not found"
exit()
end
puts "Line count: #{count_lines(pathname)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment