Bac,
I will split the source code into two replies to make it more readable.
In this
reply I will show you how you can get the drives and the type of each drive
on
your system. You will need to use some p/Invoke to call the GetDriveType()
API. For this we create a class called Win32 to place the call and an enum.
public class Win32
{
private Win32()
{
}
public enum DriveType : uint
{
Unknown = 0,
NoRootDir = 1,
Removable = 2,
Fixed = 3,
Remote = 4,
CdRom = 5,
RamDisk = 6
}
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern DriveType GetDriveType(
string rootPathName);
}
Now we have everything we need from Win32, and we can create an application
(in my case a console application) to try it out.
string[] drives = Environment.GetLogicalDrives();
foreach(string drive in drives)
{
Console.WriteLine(drive);
switch(Win32.GetDriveType(drive))
{
case Win32.DriveType.CdRom:
Console.WriteLine("CdRom");
break;
case Win32.DriveType.Fixed:
Console.WriteLine("Fixed");
break;
case Win32.DriveType.RamDisk:
Console.WriteLine("RamDisk");
break;
case Win32.DriveType.Remote:
Console.WriteLine("Remote");
break;
case Win32.DriveType.Removable:
Console.WriteLine("Removable");
break;
}
}
Console.ReadLine();
Please refer to my other reply to see how you can scan all of the folders on
a drive to get all the files.
HTH,
//Andreas