得到目录大小
uses ShellApi
function GetDirectorySize(Path: String): Integer;
//eg. Path = 'c:/temp/'
var
SR: TSearchRec;
begin
Result := 0;
if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
begin
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
Result := Result + GetDirectorySize(Path+Sr.Name+'/')
else
Result := Result + Sr.Size;
while FindNext(sr) = 0do
if (sr.Name <> '.') and (sr.Name <> '..') and (sr.Attr = faDirectory) then
Result := Result + GetdirectorySize(Path+Sr.Name+'/')
else
Result := Result + Sr.Size;
FindClose(sr);
end;
end;
得到磁盘的剩余空间:
BOOL GetDiskFreeSpace(
LPCTSTR lpRootPathName, // root path
LPDWORD lpSectorsPerCluster, // sectors per cluster
LPDWORD lpBytesPerSector, // bytes per sector
LPDWORD lpNumberOfFreeClusters, // free clusters
LPDWORD lpTotalNumberOfClusters // total clusters
);
只需要把lpSectorsPerCluster和lpBytesPerSector和lpNumberOfFreeClusters三个乘起来
就行了,得到的是字节数。