อ่านชื่อ directory เป็นภาษาไทย

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

เขียนโปรแกรมอ่านไฟล์ที่อยู่ในระบบ แต่ติดปัญหาที่ผมไม่สามารถเปรียบเทียบไฟล์ภาษาไทยได้ :’(

require 'find'
 
Find.find('d:/file') { |path|
  puts "file      => #{path} " if File.file? path
  puts "directory => #{path}" if File.directory? path
 
  puts "I can read englist" if path == "d:/file/ABC"
  puts "I can read thai" if path == "d:/file/ทดสอบ"
}

ทดลองเขียนโปรแกรมง่ายๆ แบบนี้ ตอน folder d:/file/ABC มีอ่านภาษาอังกฤษได้ แต่ตอนภาษาไทยดันไม่ยอม puts ออกมา :( ผมคาดว่าเป็นที่ file system เลยมาทดสอบบน OSX 10.5 ประกฏว่ามันอ่านไทยได้ซะงั้น ทีนี้เลยเศร้าเป็นสองเท่า

ผมลองหาทางผ่าน อ.google มีคนบอกว่า Windows ไม่ได้ส่งค้ากลับมาเป็น Unicode แบบของ *NIX และเค้าแนะนำให้ใช้ TCHAR บ้าง wchat_t บ้าง แต่ไม่เห็นมีใน ruby -> http://osdir.com/ml/lang.ruby.core/2005-03/msg00028.html?rfp=dta

พอมีใครรู้วิธีทำให้ ruby เปรียบเทียบไฟล์ภาษาไทย ได้บ้างครับ

(อ้าโชคดีที่ไม่ได้ใช้ windows)
อาจจะต้องเขียน ส่วนจัดการ file พวกนี้ ด้วย c เอง
หรือจะแอบเรียกใช้ python ดี :) http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/index.html

apirak's picture

ผมตัดสินใจบังคับให้ผู้ใช้ ใช้ภาษาอังกฤษไปก่อนล่ะ :( ไว้โปรแกรมเสร็จแล้วค่อยมาหาทางแก้กันอีกที

Apirak

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น