title: Ruby invalid byte sequence in UTF-8 (ArgumentError)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8">ruby 1.9: invalid byte sequence in UTF-8</a>  </p>
  </blockquote>
  
  
  
  <p>I'm currently building a file system crawler and receiving the following error when running my script:</p>
  
  <pre><code>wordcrawler.rb:8:in `block in &lt;main&gt;': invalid byte sequence in UTF-8 (ArgumentError)
      from /Users/Anconia/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/find.rb:41:in `block in find'
      from /Users/Anconia/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/find.rb:40:in `catch'
      from /Users/Anconia/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/find.rb:40:in `find'
      from wordcrawler.rb:5:in `&lt;main&gt;'
  </code></pre>
  
  <p>And here is my code:</p>
  
  <pre><code>require 'find'
  
  count = 0
  
  Find.find('/Users/Anconia/') do |file|                   # '/' for root directory on OS X
    if file =~ /\b(\.txt|\.doc|\.docx)\b/                # check if filename ends in desired format
      contents = File.read(file)
        if contents =~ /regex/
        puts file
        count += 1
      end
    end
  end
  
  puts "#{count} files were found"
  </code></pre>
  
  <p>In my dev environment I use ruby 1.9.3; however, when I switch to ruby 1.8.7 the script runs properly. And I'd like to continue using 1.9.3 if possible. I've tried every solution in this post (<a href="https://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8">ruby 1.9: invalid byte sequence in UTF-8</a>) but my problems still persist. Any suggestions?</p>