I am using the example from: http://msdn.microsoft.com/en-us/library/system.io.driveinfo(v=vs.80).aspx
To print drive information to a console window. I want to check if d.Name contains “T”. If it does, I wan’t to run an app. If it doesn’t do nothing. Here is the code I’ve been trying. (The default code from the above linked example prints to a command window)
(d.Name.IsLetter(T)) is the part I’m having trouble with. Can anyone advise?
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
if (d.Name.IsLetter(T))
{
Console.WriteLine("Run App.");
notePad.Start();
}//end if
else
{
Console.WriteLine("Do Nothing.");
}//end else
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);
Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);
Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}//end if
}//end for
}//end main
You want
d.Name.Contains("T")There is a
Char.IsLetter()method, but that only checks whether the argument is a “letter” (and not digit or symbol etc)