<p>I would like to generate a list of files within a directory. Some of the filenames contain Chinese characters.</p>

<p>eg: [试验].Test.txt</p>

<p>I am using the following code:</p>

<pre><code>require 'find'
dirs = ["TestDir"]
for dir in dirs
    Find.find(dir) do |path|
    if FileTest.directory?(path)
    else
        p path
    end
    end
end
</code></pre>

<p>Running the script produces a list of files but the Chinese characters are escaped (replaced with backslashes followed by numbers). Using the example filename above would produce:</p>

<p>"TestDir/[\312\324\321\351]Test.txt" instead of "TestDir/[试验].Test.txt".</p>

<p>How can the script be altered to output the Chinese characters?</p>

Ruby needs to know that you are dealing with unicode in your code. Set appropriate character encoding using KCODE, as below:
```
```
$KCODE = 'utf-8'
```
```
I think utf-8 is good enough for chinese characters.