Re: File.unlink(nonwestern_filename) ---> Error on Windows




On Jul 5, 2007, at 8:00 AM, johan556@xxxxxxxxx wrote:

Hi!

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.

I first encountered this problem when using FileUtils.rm_r, and that
method also fails (for the same reason I guess). This makes FileUtils
quite useless in some situations. We have for example Subversion
projects that contain files with Japanese characters (for testing that
our product works with such characters), and I also tried with Arabic
characters (stored in Unicode in NTFS in both cases).

Is it possible to get Ruby to work with filenames containing
non-western characters at all on Windows? If so, what should I do?

/Johan Holmberg

--------------
Dir.chdir "nonwestern-files"

for entry in Dir.entries(".")
next if entry == "."
next if entry == ".."
n = File.unlink(entry)
puts "failed to delete #{entry}" if n == 0
end
--------------


First make sure you set the KCODE

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)

.



Relevant Pages