Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <tchar.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. void DiskFreeSpace(char *DirectoryName)
  7. {
  8. ULARGE_INTEGER freeBytesAvailableToCaller;
  9. ULARGE_INTEGER totalNumberOfBytes;
  10. ULARGE_INTEGER totalNumberOfFreeBytes;
  11. HINSTANCE FHandle;
  12. FARPROC PAddress;
  13. FHandle = LoadLibrary("Kernel32");
  14. PAddress = GetProcAddress(FHandle,"GetDiskFreeSpaceEx");
  15. if (GetDiskFreeSpaceEx(DirectoryName, &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes))
  16. {
  17. /*printf("Total number of free bytes (low): %f\n", totalNumberOfFreeBytes.LowPart/1048576.0);
  18. printf("Total number of free bytes (high): %lu\n", totalNumberOfFreeBytes.HighPart*4096);*/
  19. printf("%f", totalNumberOfFreeBytes.LowPart/1048576.0 + totalNumberOfFreeBytes.HighPart*4096.0);
  20. /*printf("Free bytes available to caller(low): %f\n", freeBytesAvailableToCaller.LowPart/1048576.0);
  21. printf("Free bytes available to caller(high): %lu\n", freeBytesAvailableToCaller.HighPart*4096);*/
  22. /*printf("Free bytes available to caller: %f MB\n", freeBytesAvailableToCaller.LowPart/1048576.0 + freeBytesAvailableToCaller.HighPart*4096.0);
  23. /*printf("Total number of bytes (low): %f\n", totalNumberOfBytes.LowPart/1048576.0);
  24. printf("Total number of bytes (high): %lu\n", totalNumberOfBytes.HighPart*4096);
  25. printf("Total number of bytes: %f MB\n",totalNumberOfBytes.LowPart/1048576.0 + freeBytesAvailableToCaller.HighPart*4096.0);*/
  26. }
  27. else
  28. {
  29. printf("Error");
  30. }
  31. }
  32. void __cdecl main(int arc, char *argv[])
  33. {
  34. char *Path;
  35. /* Path is the second argument in the command line when calling the executable "freespace" */
  36. Path = argv[1];
  37. DiskFreeSpace(Path);
  38. }