Guest User

Untitled

a guest
May 27th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. require 'find'
  2. require 'optparse'
  3.  
  4. # Create option parser.
  5. options = {}
  6. ARGV.options do |opts|
  7. opts.banner << " <path>"
  8. opts.on("-v", "--[no-]verbose", "run verbosely") do |v|
  9. options[:verbose] = v
  10. end
  11. end.parse!
  12.  
  13. # Check for required path argument.
  14. path = ARGV[0] or (STDERR.puts ARGV.options; exit 2)
  15.  
  16. # Recursively scan files for the first bytes.
  17. Find.find(path) do |fn|
  18. next if not File.file?(fn)
  19. has_bom = File.open(fn) {|f| f.read(3)} == "\xEF\xBB\xBF"
  20. if options[:verbose]
  21. # List every scanned file and the corresponding result.
  22. puts fn << " ... " << (has_bom ? "BOM found." : "no BOM.")
  23. elsif has_bom
  24. # Only list names of files with BOMs found.
  25. puts fn
  26. end
  27. end
Add Comment
Please, Sign In to add comment