Ruby で、チェックツールを作った

隠しファイル・ディレクトリは、どう扱うのか?
ファイル名に、. がある場合に、どうするのか?

require 'pathname'

p base_dir = Pathname.new( "C:/Users/Owner/Documents/test/" )

folders = base_dir.children.select( &:directory? ) # 直下のディレクトリのみ
p folders.length, folders

files = folders.map { |folder| folder.children.select( &:file? ).first } # 直下の最初のファイルのみ

# nil は、直下にファイルが存在しない、ディレクトリ
nil_cnt = files.count( &:nil? )
p files.length, nil_cnt, files

# compact で、nil の要素を省く
hash = files.compact.each_with_object( { } ) do |file, hash|
filename = file.basename.to_s # ファイル名を、ハッシュに追加していく
if hash.has_key? filename # ハッシュに、既に追加されていれば
hash[ filename ] += 1
else
hash[ filename ] = 1
end
end

# 2 以上のもの、つまり、同じファイル名になったものを表示する
p hash, hash.select { |key, val| val >= 2 }