Re: File.unlink(nonwestern_filename) ---> Error on Windows
- From: John Joyce <dangerwillrobinsondanger@xxxxxxxxx>
- Date: Thu, 5 Jul 2007 23:12:04 +0900
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)
.
- Follow-Ups:
- Re: File.unlink(nonwestern_filename) ---> Error on Windows
- From: johan556
- Re: File.unlink(nonwestern_filename) ---> Error on Windows
- References:
- File.unlink(nonwestern_filename) ---> Error on Windows
- From: johan556
- File.unlink(nonwestern_filename) ---> Error on Windows
- Prev by Date: Re: [SUMMARY] LSRC Name Picker (#129)
- Next by Date: Re: Destroy object from memory.. Object.const_destroy?
- Previous by thread: File.unlink(nonwestern_filename) ---> Error on Windows
- Next by thread: Re: File.unlink(nonwestern_filename) ---> Error on Windows
- Index(es):
Relevant Pages
|