Disk capacity and free space

I am sorry because it is not contents of CPU module etc., but it is very helpful if you can tell me.

Please let me know how to use the .NET Compact Framework 3.5 with WEC 7 to acquire the disk capacity of the RAM disk and USB memory and the free disk space at high speed.

It is a system that saves a lot of files in the USB memory, but in order to detect the lack of free space in advance.

When the number of files and the number of folders becomes large, processing time takes too much with the mechanism of calculating the size of each file.

Dear @kyas

There’s a native Win32 function GetDiskFreeSpaceEx() to accomplish that task. In order to use it from .NET CF you need to PInvoke this function, as follows:

public class Disk
{
  [DllImport("coredll.dll", SetLastError=true, CharSet=CharSet.Auto)]
  [return: MarshalAs(UnmanagedType.Bool)]
  internal static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
    out ulong lpFreeBytesAvailable,
    out ulong lpTotalNumberOfBytes,
    out ulong lpTotalNumberOfFreeBytes);
}

Calling the function looks as follows:

void GetDiskSize(string volumeName)
{
  ulong available;
  ulong total;
  ulong totalfree;

  Disk.GetDiskFreeSpaceEx(volumeName, out available, out total, out totalFree);
}

Note 1:
I didn’t test the code. In theory it should work.

Note 2:
Please be aware, that all flash-based memories only feature a limited number of write cycles. Writing at high speed to any flash memory could damage the storage. This is especially true if a storage device has little free memory, and if the device uses only simple wear leveling algorithms.

Regards, Andy

Thank you so much for replying to such questions as well.
Try immediately.