![]() |
|
[Ruby] File Stats - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [Ruby] File Stats (/Thread-Ruby-File-Stats) |
[Ruby] File Stats - Inori - 04-03-2015 As mentioned in my previous thread, I made a number of things on my flight. The second is a pretty compact file statistics tool. Good for an Essay written in some off-brand text editor or some code you want in-depth stats for. There's not much I can see myself adding so I don't think I'll be updating this much. Anyway, enjoy! Code: #WordCount by Nightc||ed, ©2015
counta = 0
countb = 0
puts "Enter file name:"
file = gets.chomp
sspace = File.size("#{file}")
File.foreach("#{file}") { |line|
counta += line.scan(/[a-z0-9A-Z]+/).size
countb += line.scan(/[a-z0-9A-z ]/).size
}
system "cls"
puts "Stats for #{file}:
•contains #{counta} words
contains #{countb} standard characters
is #{sspace} Bytes in size"
sleep |