123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- {
- $Id$
- This file is part of the Free Pascal run time library.
- Copyright (c) 1999-2000 by the Free Pascal development team
- Disk functions from Delphi's sysutils.pas
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- function GetDiskFreeSpace(drive:pchar;var sector_cluster,bytes_sector,
- freeclusters,totalclusters:longint):longbool;
- external 'kernel32' name 'GetDiskFreeSpaceA';
- type
- TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,
- total,free):longbool;stdcall;
- var
- GetDiskFreeSpaceEx : TGetDiskFreeSpaceEx;
- function diskfree(drive : byte) : int64;
- var
- disk : array[1..4] of char;
- secs,bytes,
- free,total : longint;
- qwtotal,qwfree,qwcaller : int64;
- begin
- if drive=0 then
- begin
- disk[1]:='\';
- disk[2]:=#0;
- end
- else
- begin
- disk[1]:=chr(drive+64);
- disk[2]:=':';
- disk[3]:='\';
- disk[4]:=#0;
- end;
- if assigned(GetDiskFreeSpaceEx) then
- begin
- if GetDiskFreeSpaceEx(@disk,qwcaller,qwtotal,qwfree) then
- diskfree:=qwfree
- else
- diskfree:=-1;
- end
- else
- begin
- if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
- diskfree:=int64(free)*secs*bytes
- else
- diskfree:=-1;
- end;
- end;
- function disksize(drive : byte) : int64;
- var
- disk : array[1..4] of char;
- secs,bytes,
- free,total : longint;
- qwtotal,qwfree,qwcaller : int64;
- begin
- if drive=0 then
- begin
- disk[1]:='\';
- disk[2]:=#0;
- end
- else
- begin
- disk[1]:=chr(drive+64);
- disk[2]:=':';
- disk[3]:='\';
- disk[4]:=#0;
- end;
- if assigned(GetDiskFreeSpaceEx) then
- begin
- if GetDiskFreeSpaceEx(@disk,qwcaller,qwtotal,qwfree) then
- disksize:=qwtotal
- else
- disksize:=-1;
- end
- else
- begin
- if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
- disksize:=int64(total)*secs*bytes
- else
- disksize:=-1;
- end;
- end;
- Function GetCurrentDir : String;
- begin
- GetDir(0, result);
- end;
- Function SetCurrentDir (Const NewDir : String) : Boolean;
- begin
- {$I-}
- ChDir(NewDir);
- result := (IOResult = 0);
- {$I+}
- end;
- Function CreateDir (Const NewDir : String) : Boolean;
- begin
- {$I-}
- MkDir(NewDir);
- result := (IOResult = 0);
- {$I+}
- end;
- Function RemoveDir (Const Dir : String) : Boolean;
- begin
- {$I-}
- RmDir(Dir);
- result := (IOResult = 0);
- {$I+}
- end;
- {
- $Log$
- Revision 1.1 2000-07-13 06:31:19 michael
- + Initial import
- Revision 1.5 2000/05/15 19:28:41 peter
- * int64 support for diskfree,disksize
- Revision 1.4 2000/02/09 16:59:34 peter
- * truncated log
- Revision 1.3 2000/01/07 16:41:52 daniel
- * copyright 2000
- }
|