holy_spirit

hi all, i want to get the logical drives.

so i use

Environment.GetLogicalDrives();

but this method gave me the logical drives including the drives that conected to my pc

like (USBs..)

so i wanna another method that can give me only the basic logical drives on my system

is it possible.

thanx for your help.



Re: Visual C# General Logical Drives ?

Peter Ritchie

It would entirely depend on your criteria; but you can use DriveInfo.DriveType to check what type of drive a particular drive is. For example:

Code Snippet
String[] drives = Environment.GetLogicalDrives();
foreach(string drive in drives)
{
DriveInfo driveInfo = new DriveInfo(drive);
Console.WriteLine(driveInfo.DriveType.ToString());
}







Re: Visual C# General Logical Drives ?

holy_spirit


thanx but that is not my question
look
if my hard disk have (C D E) drives
and there is a USB (flash memory) attached to my pc too
then the Environment.GetLogicalDrives();will give me (C D E F) which (F) is the removable disk, i know that ... so here is my question :
how can i get only the primary drives of my hard (C D E)
without getting (F)
i wont use Environment.GetLogicalDrives(); then get only the three elements of the Array result, no
i need method that giving me the (C D E) drives direct
is it clear





Re: Visual C# General Logical Drives ?

boban.s

string partitionsString = "";

List<string> partitionsList = new List<string>();

String[] drives = Environment.GetLogicalDrives();

foreach (string drive in drives)

{

DriveInfo driveInfo = new DriveInfo(drive);

if (driveInfo.DriveType == DriveType.Fixed)

{

partitionsString += driveInfo.Name.Split(':')[0] + " ";

partitionsList.Add(driveInfo.Name.Split(':')[0]);

}

}

//partitionsString will contain "C D E "

//partitionsList will have list of strings filled with three string items "C" "D" and "E"






Re: Visual C# General Logical Drives ?

Peter Ritchie

As boban pointed out, you can't just get certain logical drives, you have to check which logical drives are the drives you want to deal with. That's done with the DriveInfo class.




Re: Visual C# General Logical Drives ?

holy_spirit

Peter Ritchie : you can't just get certain logical drives

okay thanx, i expect that.

thanx for every body

this topic is closed