<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: count code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 16:31:05 GMT</pubDate>
    <description>DZone Snippets: count code</description>
    <item>
      <title>howmany</title>
      <link>http://snippets.dzone.com/posts/show/5211</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;#==========================================================================================&lt;br /&gt;# howmany -- a tool for determining how many different types of files are in a folder&lt;br /&gt;#------------------------------------------------------------------------------------------&lt;br /&gt;# Author: Elliot Winkler &lt;elliot.winkler@gmail.com&gt;&lt;br /&gt;# Created: 11 Mar 2008&lt;br /&gt;#==========================================================================================&lt;br /&gt;&lt;br /&gt;my $dir = $ARGV[0] || ".";&lt;br /&gt;my $cmd = "find $dir";&lt;br /&gt;my @listing = sort grep { $_ } split /\n/, `$cmd`;&lt;br /&gt;&lt;br /&gt;my %exts;&lt;br /&gt;for (@listing) {&lt;br /&gt;  my($ext) = /\.([a-z]+)$/;&lt;br /&gt;  next unless $ext;&lt;br /&gt;  $exts{lc $ext}++;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;for (sort keys %exts) {&lt;br /&gt;  print uc($_).": ".$exts{$_}."\n";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ cd ~/docs&lt;br /&gt;$ howmany&lt;br /&gt;CSV: 3&lt;br /&gt;DOC: 1&lt;br /&gt;KEY: 1&lt;br /&gt;PUB: 1&lt;br /&gt;SQL: 1&lt;br /&gt;TEXT: 1&lt;br /&gt;TXT: 9&lt;br /&gt;XCF: 2&lt;br /&gt;XLS: 1&lt;br /&gt;ZIP: 1&lt;br /&gt;$ howmany ~/docs&lt;br /&gt;CSV: 3&lt;br /&gt;DOC: 1&lt;br /&gt;KEY: 1&lt;br /&gt;PUB: 1&lt;br /&gt;SQL: 1&lt;br /&gt;TEXT: 1&lt;br /&gt;TXT: 9&lt;br /&gt;XCF: 2&lt;br /&gt;XLS: 1&lt;br /&gt;ZIP: 1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; This only works on Linux/Unix, because it relies on a Linux/Unix-only command to pull up the list of files. A future update may include support for Windows, though it would be pretty easy to find out how to fix it.</description>
      <pubDate>Tue, 11 Mar 2008 14:57:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5211</guid>
      <author>mcmire ()</author>
    </item>
  </channel>
</rss>
