title: How can I determine free space on a Windows CE device?
body: <p>I need to determine how much free space there is on a Windows CE device, to conditionally determine whether a particular operation should proceed.</p>
  
  <p>I thought Ken Blanco's answer <a href="https://stackoverflow.com/questions/1799984/finding-out-total-and-free-disk-space-in-net">here</a> (which bears a striking similarity to the example <a href="http://msdn.microsoft.com/en-us/library/system.io.driveinfo(v=vs.90).aspx" rel="nofollow noreferrer">yonder</a>) would work, which I adapted as:</p>
  
  <pre><code>internal static bool EnoughStorageSpace(long spaceNeeded)
  {
      DriveInfo[] allDrives = DriveInfo.GetDrives();
      long freeSpace = 0;
      foreach (DriveInfo di in allDrives)
      {
          if (di.IsReady)
          {
              freeSpace = di.AvailableFreeSpace;
          }
      }
      return freeSpace &gt;= spaceNeeded;
  }
  </code></pre>
  
  <p>...but <em>DriveInfo</em> is not available in my Windows CE / compact framework project.</p>
  
  <p>I am referencing mscorlib, and am using System.IO, but as DriveInfo is redder than a Kansas City Chiefs jersey in my editor, I reckon it's not available to me.</p>
  
  <p>Is there an alternative way of accomplishing the same thing?</p>
  
  <h2>UPDATE</h2>
  
  <p>I adapted this:</p>
  
  <pre><code>[DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
  [return: MarshalAs(UnmanagedType.Bool)]
  static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
  out ulong lpFreeBytesAvailable,
  out ulong lpTotalNumberOfBytes,
  out ulong lpTotalNumberOfFreeBytes);
  
  public static bool EnoughStorageSpace(ulong freespaceNeeded)
  {
      String folderName = "C:\\";
      ulong freespace = 0;
      if (string.IsNullOrEmpty(folderName))
      {
          throw new ArgumentNullException("folderName");
      }    
  
      ulong free, dummy1, dummy2;
  
      if (GetDiskFreeSpaceEx(folderName, out free, out dummy1, out dummy2))
      {
          freespace = free;
      }
      return freespace &gt;= freespaceNeeded;
  }
  </code></pre>
  
  <p>...from <a href="http://pinvoke.net/default.aspx/kernel32.GetDiskFreeSpaceEx" rel="nofollow noreferrer">here</a>, which compiles, but I don't know what "folderName" should be for a Windows CE device; in Windows Explorer, it has no name at all. I'm sure what I have as of now ("C:\") is not right...</p>
  
  <h2>UPDATE 2</h2>
  
  <p>According to "Windows programmer" <a href="https://stackoverflow.com/questions/151860/root-folder-equivalent-in-windows">here</a>: "<em>If you're running Windows CE then \ is the root directory</em>"</p>
  
  <p>So, should I use:</p>
  
  <pre><code>String folderName = "\";
  </code></pre>
  
  <p>...or do I need to escape it:</p>
  
  <pre><code>String folderName = "\\";
  </code></pre>
  
  <p>...or...???</p>