Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'find'
- require 'optparse'
- # Create option parser.
- options = {}
- ARGV.options do |opts|
- opts.banner << " <path>"
- opts.on("-v", "--[no-]verbose", "run verbosely") do |v|
- options[:verbose] = v
- end
- end.parse!
- # Check for required path argument.
- path = ARGV[0] or (STDERR.puts ARGV.options; exit 2)
- # Recursively scan files for the first bytes.
- Find.find(path) do |fn|
- next if not File.file?(fn)
- has_bom = File.open(fn) {|f| f.read(3)} == "\xEF\xBB\xBF"
- if options[:verbose]
- # List every scanned file and the corresponding result.
- puts fn << " ... " << (has_bom ? "BOM found." : "no BOM.")
- elsif has_bom
- # Only list names of files with BOMs found.
- puts fn
- end
- end
Add Comment
Please, Sign In to add comment