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.