Forum: JRuby non latin characters and File(x).size

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vitaliy S. (Guest)
on 2009-01-22 17:19
Hello.
I use Ruby(mswin32/cygwin)/JRuby on Windows platform.
I can't get File(x).size if file name (x) contains non latin characters
such as some french ("ç") or russian letters.

Code:
#!/bin/ruby
$KCODE = 'u'
require 'jcode'

def get_filelist(dir_path = "D:/books" ,filename = "data.txt", mask =
"**/*{.pdf,.djvu,.chm}")
  f = File.open(filename, "w")
  Dir.chdir(dir_path)
  workdir = Dir.getwd
  allbooks = Dir.glob(mask)

  allbooks.each { |x|
    begin
      size = "unknown"
      size = File.size(x).to_s
    rescue
# if I remove "rescue" I will get the error message like this
# main.rb:18:in `get_filelist': No such file or directory
# - No such file or directory - Grammaire Fran???§aise.pdf
(Errno::ENOENT)
    end
    f.puts(x + "<<" + size + ">>")
  }
  f.close
end

get_filelist()


What am I doing wrong?
Regards.
This topic is locked and can not be replied to.