From: johan556@... Date: 2007-07-06T01:32:01+09:00 Subject: Re: File.unlink(nonwestern_filename) ---> Error on Windows On 7/5/07, John Joyce wrote: > On Jul 5, 2007, at 8:00 AM, johan556@gmail.com wrote: > > > > I use Ruby on Windows, and tried to remove all files in a directory > > with the code given below. But if the directory contains files with > > filenames having non-western characters the operation fails. > > > > First make sure you set the KCODE > Using KCODE does not change anything. I have tried: $ ruby -Ke rm-files.rb $ ruby -Ks rm-files.rb $ ruby -Ku rm-files.rb $ ruby -Ka rm-files.rb $ ruby -Kn rm-files.rb The problematic files are stored with a name that is a 16-bit character string in NTFS (what I called Unicode in my earlier mail, perhaps one should call it "almost UTF-16" or UCS-2, I don't know the finer details). Anyway, I don't think setting KCODE solves my problem. > Try using the chars class from ActiveSupport (yes it is a gem that is > part of Rails but it provides a great deal of utf-8 processing) > See above. I don't think NTFS stores Unicode filenames in UTF-8. My assumption when starting to look at this problem was: that a filename that I got from one function (Dir.entries) would be directly usable in another function (File.unlink). That was quite naive I realize :) But it is still a real problem. As it is now, FileUtils.rm_r does not work on an arbitrary file-tree. As soon as it contains a file with "wrong" filename it fails. Maybe this is just a consequence of the way Ruby is ported to Windows. /Johan Holmberg