System.IO.DriveInfoInternal.GetLogicalDrives C# (CSharp) Méthode

GetLogicalDrives() public static méthode

public static GetLogicalDrives ( ) : string[]
Résultat string[]
        public static string[] GetLogicalDrives()
        {
            int drives = Interop.Kernel32.GetLogicalDrives();
            if (drives == 0)
                throw Win32Marshal.GetExceptionForLastWin32Error();

            // GetLogicalDrives returns a bitmask starting from 
            // position 0 "A" indicating whether a drive is present.
            // Loop over each bit, creating a string for each one
            // that is set.

            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;
        }
    }

Usage Example

 public static DriveInfo[] GetDrives()
 {
     string[]    drives = DriveInfoInternal.GetLogicalDrives();
     DriveInfo[] result = new DriveInfo[drives.Length];
     for (int i = 0; i < drives.Length; i++)
     {
         result[i] = new DriveInfo(drives[i]);
     }
     return(result);
 }
All Usage Examples Of System.IO.DriveInfoInternal::GetLogicalDrives
DriveInfoInternal