[Mono-list] GetDirectories, glob, and high ACSII characters

Elan Feingold efeingold@mn.rr.com
Mon, 10 Mar 2003 11:59:14 -0600


Holy cow, that took a long time to find what's going on...

The problem occurs when calling GetDirectories() when there are
directories with "high ASCII" characters (like "M=E9lodie Citronique").

The function glob(), which is used in FindFirstFile(), uses fnmatch(),
which uses mbsrtowcs(), to convert a multibyte string to a wide
character string.

I did not have any locale-related environment variables set. Since mono
calls setlocale(LC_ALL, ""), this results in mbsrtowcs() failing for
file names with extended characters.

If I set a LC_CTYPE, say to "C", the files make their way past
fnmatch(), but then there's a crash in FindNextFile(), where it tries to
convert g_utf8_to_utf16 and fails (perhaps because the input isn't
UTF8?). I tried adding a call to g_locale_to_utf8() but this failed as
well.

Help!!!! Can someone else shed some light on this? Easy to reproduce,
just create a directory with an accented character, and then run this
source.

What is my LC_CTYPE and other locale environment variables supposed to
be set to?

using System.IO;
using System;

class C
{
    static void Main()
    {
        string dir =3D "./";

        DirectoryInfo dirInfo =3D new DirectoryInfo(dir);
        DirectoryInfo[] subDirs =3D dirInfo.GetDirectories();

        foreach (DirectoryInfo subDir in subDirs)
        {
            Console.WriteLine("Directory is: {0}.",  subDir.Name);
        }
    }
}