Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:36:32+00:00 2026-06-05T04:36:32+00:00

I can not copy files that have Unicode characters in their names from Ruby

  • 0

I can not copy files that have Unicode characters in their names from Ruby 1.9.2p290, on Windows 7.

For example, I have two files in a dir:

file
ハリー・ポッターと秘密の部屋

(The second name contains Japanese characters if you can not see it)

Here is the code:

> entries = Dir.entries(path) - %w{ . .. }
> entries[0]
=> "file"
> entries[1]
=> "???????????????" # <--- what?

> File.file? entries[0]
=> true
> File.file? entries[1]
=> false   # <---  !!! Ruby can not see it and will not copy

> entries[1].encoding.name
=> "Windows-1251"
> Encoding.find('filesystem').name
=> "Windows-1251"

As you see my Ruby file system encoding is “windows-1251” which is 8 bit and can not handle Japanese. Setting default_external and default_internal encodings to ‘utf-8’ does not help.

How can I copy those files from Ruby?

Update

I found a solution. It works if I use Dir.glob or Dir[] instead of Dir.entries. File names are now returned in utf-8 encoding and can be copied.

Update #2

My Dir.glob solution appears to be quite limited. It only works with “*” parameter:

Dir.glob("*") # <--- Shows Unicode names correctly
Dir.glob("c:/test/*") # <--- Does not work for Unicode names
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:36:33+00:00Added an answer on June 5, 2026 at 4:36 am

    Not so much a real solution, but as a workaround, given:

    Dir.glob("*") # <--- Shows Unicode names correctly
    Dir.glob("c:/test/*") # <--- Does not work for Unicode names
    

    is there any reason you can’t do this:

    Dir.chdir("c:/test/")
    Dir.glob("*")
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a application that can copy files to places in two TreeViews
I have created a gui with powershell that allows me to copy files from
How can I get tar/cp to copy only files that dont end in .jar
How can I copy the visible page of a WebBrowser control? Not the HTML,
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
I can not get logs from some customers, can I use Google Urchin in
I have a Scripts folder, that includes all the .js files used in the
I'm writing an application which can copy files on a network share. Usually the
I want to copy F:\test to folder F:\123 so that I have folder F:\123\test.
I need to copy multiple files in a single batch file. The files have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.