// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Linq; namespace E { public class Program { private const string DRIVES = "ABCDEFGHIJKLMOPQRSTUWVXYZ"; public static char FirstUnusedDrive2() { DriveInfo[] dia = DriveInfo.GetDrives(); foreach(char d in DRIVES) { foreach(DriveInfo di in dia) { if(di.Name[0] == d) { goto nomatch; } } return d; nomatch: ; } throw new ApplicationException("No unused drive letters"); } public static char FirstUnusedDrive3() { DriveInfo[] dia = DriveInfo.GetDrives(); var q = from d in DRIVES where !(from di in dia select di.Name[0]).Contains(d) select d; return q.First(); } public static void Main(string[] args) { Console.WriteLine(FirstUnusedDrive2()); Console.WriteLine(FirstUnusedDrive3()); } } }