disk.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. function diskfree(drive : byte) : longint;
  16. var
  17. disk : array[1..4] of char;
  18. secs,bytes,
  19. free,total : longint;
  20. begin
  21. if drive=0 then
  22. begin
  23. disk[1]:='\';
  24. disk[2]:=#0;
  25. end
  26. else
  27. begin
  28. disk[1]:=chr(drive+64);
  29. disk[2]:=':';
  30. disk[3]:='\';
  31. disk[4]:=#0;
  32. end;
  33. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  34. result:=free*secs*bytes
  35. else
  36. result:=-1;
  37. end;
  38. function disksize(drive : byte) : longint;
  39. var
  40. disk : array[1..4] of char;
  41. secs,bytes,
  42. free,total : longint;
  43. begin
  44. if drive=0 then
  45. begin
  46. disk[1]:='\';
  47. disk[2]:=#0;
  48. end
  49. else
  50. begin
  51. disk[1]:=chr(drive+64);
  52. disk[2]:=':';
  53. disk[3]:='\';
  54. disk[4]:=#0;
  55. end;
  56. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  57. result:=total*secs*bytes
  58. else
  59. result:=-1;
  60. end;
  61. Function GetCurrentDir : String;
  62. begin
  63. GetDir(0, result);
  64. end;
  65. Function SetCurrentDir (Const NewDir : String) : Boolean;
  66. begin
  67. {$I-}
  68. ChDir(NewDir);
  69. result := (IOResult = 0);
  70. {$I+}
  71. end;
  72. Function CreateDir (Const NewDir : String) : Boolean;
  73. begin
  74. {$I-}
  75. MkDir(NewDir);
  76. result := (IOResult = 0);
  77. {$I+}
  78. end;
  79. Function RemoveDir (Const Dir : String) : Boolean;
  80. begin
  81. {$I-}
  82. RmDir(Dir);
  83. result := (IOResult = 0);
  84. {$I+}
  85. end;
  86. {
  87. $Log$
  88. Revision 1.4 2000-02-09 16:59:34 peter
  89. * truncated log
  90. Revision 1.3 2000/01/07 16:41:52 daniel
  91. * copyright 2000
  92. }