LoginSignup
3
3

More than 5 years have passed since last update.

Windows 環境で Ruby を2.3に更新したら Dir::glob が日本語のファイルを列挙してくれなくなった→解決

Last updated at Posted at 2016-02-20

もともとRuby1.9.3環境で動かしていたスクリプトが、Windows10インストールのついでにRuby2.3 に更新したら動かなくなったので直してみた。
コメントでご指摘いただいたのですが、ひょっとしたらRubyのバージョンの話ではなく、OSのバージョンとか、インストールしたRubyパッケージが別物だからという理由かもしれません。
が、ちゃんと検証してないので不明です。すみません。。。

ちなみに、もともとの環境が下記。

Windows7 x64
Ruby 1.9.3 p362
http://rubyinstaller.org/

で、更新後の環境は下記になります。

Windows10 x64
Ruby 2.3.0 p0
http://www.artonx.org/data/asr/

動かなくなった箇所はDir::globでファイルを列挙している部分。

もともとのスクリプト

#!/bin/ruby
targetFiles = "#{ARGV[0]}/*.ts"
Dir::glob(targetFiles).each {|f|
...
...

修正後は以下のような感じ。

#!/bin/ruby
targetFiles = File.expand_path("#{ARGV[0]}/*.ts")
Dir::glob(targetFiles.encode('utf-8')).each {|f|
...
...

これでおkでした。

ちなみに、スクリプトの呼び出しはこんな感じで使ってます

> encode.rb d:/rec
3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3