rewrite directory scanner in ruby
eliminate duplication