Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ enumeration of local dirves using DriveInfo
    primarykey
    data
    text
    <p>I know there are many ways to accomplish what I am trying to do here, but I wanted to try it with LINQ, and am seeing some odd (to me) results. Hoping someone here has some wisdom to offer me.</p> <p>Goal is to find the drive on the local machine where we execute with the most available free space that has been formatted to NTFS file system, excluding the %SystemDrive% volume if possible. Another caveat is that drives that are assigned a volume letter, but have not yet been formatted must be excluded from the candidate pool. This is an edge case, but one customer has already encountered it.</p> <p>So, I am trying:</p> <pre><code>string systemDrive = Environment.GetEnvironmentVariable("SystemDrive") + "\\"; List&lt;DriveInfo&gt; localDrives = DriveInfo.GetDrives().ToList(); var bestAPIDataDrives = from localDrive in localDrives orderby localDrive.AvailableFreeSpace descending where localDrive.DriveType == DriveType.Fixed &amp;&amp; localDrive.DriveFormat == "NTFS" &amp;&amp; localDrive.RootDirectory.FullName != systemDrive &amp;&amp; localDrive.IsReady select localDrive.RootDirectory.FullName; string path = String.Empty; if (bestAPIDataDrives.Count() == 0) { // there is only a system drive available, use it anyway. path = systemDrive; } else { path = bestAPIDataDrives.ElementAt(0).ToString(); } </code></pre> <p>When I get to the bestAPIDataDrives.Count() reference, I get an IOException with Message property set to "The device is not ready".</p> <p>I don't see why this is happening because I have the localDrive.IsReady test in the LINQ query, or at least I think I do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload