Search code examples
f#sequences

Get a list of invalid drive letters


let private GetDrives = seq{
let all=System.IO.DriveInfo.GetDrives()
for d in all do
    //if(d.IsReady && d.DriveType=System.IO.DriveType.Fixed) then
        yield d
}

let valid={'A'..'Z'}
let rec SearchRegistryForInvalidDrive (start:RegistryKey) = seq{
    let validDrives=GetDrives |> Seq.map (fun x -> x.Name.Substring(0,1))
    let invalidDrives= Seq.toList validDrives |> List.filter(fun x-> not (List.exists2 x b)) //(List.exists is the wrong method I think, but it doesn't compile

I followed F#: Filter items found in one list from another list but could not apply it to my problem as both the solutions I see don't seem to compile. List.Contains doesn't exist (missing a reference?) and ListA - ListB doesn't compile either.


Solution

  • open System.IO
    let driveLetters = set [ for d in DriveInfo.GetDrives() -> d.Name.[0] ]
    let unused = set ['A'..'Z'] - driveLetters