disk.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Disk functions from Delphi's sysutils.pas
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. function GetDiskFreeSpace(drive:pchar;var sector_cluster,bytes_sector,
  13. freeclusters,totalclusters:longint):longbool;
  14. external 'kernel32' name 'GetDiskFreeSpaceA';
  15. type
  16. TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,
  17. total,free):longbool;stdcall;
  18. var
  19. GetDiskFreeSpaceEx : TGetDiskFreeSpaceEx;
  20. function diskfree(drive : byte) : int64;
  21. var
  22. disk : array[1..4] of char;
  23. secs,bytes,
  24. free,total : longint;
  25. qwtotal,qwfree,qwcaller : int64;
  26. begin
  27. if drive=0 then
  28. begin
  29. disk[1]:='\';
  30. disk[2]:=#0;
  31. end
  32. else
  33. begin
  34. disk[1]:=chr(drive+64);
  35. disk[2]:=':';
  36. disk[3]:='\';
  37. disk[4]:=#0;
  38. end;
  39. if assigned(GetDiskFreeSpaceEx) then
  40. begin
  41. if GetDiskFreeSpaceEx(@disk,qwcaller,qwtotal,qwfree) then
  42. diskfree:=qwfree
  43. else
  44. diskfree:=-1;
  45. end
  46. else
  47. begin
  48. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  49. diskfree:=int64(free)*secs*bytes
  50. else
  51. diskfree:=-1;
  52. end;
  53. end;
  54. function disksize(drive : byte) : int64;
  55. var
  56. disk : array[1..4] of char;
  57. secs,bytes,
  58. free,total : longint;
  59. qwtotal,qwfree,qwcaller : int64;
  60. begin
  61. if drive=0 then
  62. begin
  63. disk[1]:='\';
  64. disk[2]:=#0;
  65. end
  66. else
  67. begin
  68. disk[1]:=chr(drive+64);
  69. disk[2]:=':';
  70. disk[3]:='\';
  71. disk[4]:=#0;
  72. end;
  73. if assigned(GetDiskFreeSpaceEx) then
  74. begin
  75. if GetDiskFreeSpaceEx(@disk,qwcaller,qwtotal,qwfree) then
  76. disksize:=qwtotal
  77. else
  78. disksize:=-1;
  79. end
  80. else
  81. begin
  82. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  83. disksize:=int64(total)*secs*bytes
  84. else
  85. disksize:=-1;
  86. end;
  87. end;
  88. Function GetCurrentDir : String;
  89. begin
  90. GetDir(0, result);
  91. end;
  92. Function SetCurrentDir (Const NewDir : String) : Boolean;
  93. begin
  94. {$I-}
  95. ChDir(NewDir);
  96. result := (IOResult = 0);
  97. {$I+}
  98. end;
  99. Function CreateDir (Const NewDir : String) : Boolean;
  100. begin
  101. {$I-}
  102. MkDir(NewDir);
  103. result := (IOResult = 0);
  104. {$I+}
  105. end;
  106. Function RemoveDir (Const Dir : String) : Boolean;
  107. begin
  108. {$I-}
  109. RmDir(Dir);
  110. result := (IOResult = 0);
  111. {$I+}
  112. end;
  113. {
  114. $Log$
  115. Revision 1.1 2000-07-13 06:31:19 michael
  116. + Initial import
  117. Revision 1.5 2000/05/15 19:28:41 peter
  118. * int64 support for diskfree,disksize
  119. Revision 1.4 2000/02/09 16:59:34 peter
  120. * truncated log
  121. Revision 1.3 2000/01/07 16:41:52 daniel
  122. * copyright 2000
  123. }