I cannot copy files with Unicode characters in their names from Ruby 1.9.2p290 on Windows 7.
For example, I have two files in a directory:
file
ハリー・ポッターと秘密の部屋
(The middle name contains Japanese characters if you do not see it)
Here is the code:
> entries = Dir.entries(path) - %w{ . .. }
> entries[0]
=> "file"
> entries[1]
=> "???????????????"
> File.file? entries[0]
=> true
> File.file? entries[1]
=> false
> entries[1].encoding.name
=> "Windows-1251"
> Encoding.find('filesystem').name
=> "Windows-1251"
As you can see, my Ruby file system encoding is “windows-1251”, which has 8 bits and cannot handle Japanese. Setting default_externaland default_internalencodings to "utf-8" does not help.
How to copy these files from Ruby?
Update
I have found a solution. It works if I use Dir.globor Dir[]instead of Dir.entries. File names are now returned in utf-8 encoding and can be copied.
Update # 2
My Dir.glob . "*":
Dir.glob("*")
Dir.glob("c:/test/*")