コード例 #1
0
ファイル: IOServices.cs プロジェクト: rsumner31/corefx2
    private static string[] GetLogicalDrives()
    {   // From .NET Framework's Directory.GetLogicalDrives
        int drives = DllImports.GetLogicalDrives();

        if (drives == 0)
        {
            throw new InvalidOperationException();
        }

        uint d     = (uint)drives;
        int  count = 0;

        while (d != 0)
        {
            if (((int)d & 1) != 0)
            {
                count++;
            }
            d >>= 1;
        }
        string[] result = new string[count];
        char[]   root   = new char[] { 'A', ':', '\\' };
        d     = (uint)drives;
        count = 0;
        while (d != 0)
        {
            if (((int)d & 1) != 0)
            {
                result[count++] = new string(root);
            }
            d >>= 1;
            root[0]++;
        }

        return(result);
    }