空ディレクトリに.gitignoreを

#! /usr/bin/env ruby
require "find"
require "fileutils"
GIT_IGNORE_FILE = '.gitignore'
EMPTY_DIR_ENTRIES = ['.', '..']
Find.find('.') do |path|
  next unless File.directory?(path)
  Find.prune if File.basename(path) == '.git'
  next if (Dir.entries(path) - EMPTY_DIR_ENTRIES).length > 0
  FileUtils.touch(File.join(path, GIT_IGNORE_FILE), :verbose => true)
end

railsコマンドを打った後、gitに空のディレクトリも全部コミットしたい場合に使えるかも。
実行するとカレントディレクトリ配下の空のディレクトリにいちいち.gitignoreファイルを作ります。
他にいい方法があったら教えてください。


Dir.glob使う方法を考えているのですが思いつかないっす。