Τετάρτη 8 Μαΐου 2013

Get folder size

This function tells you how many bytes a folder, with all subfolders and contained files is taking.


function FolderSize(folderPath: string): dword;
var
  searchRec: tsearchrec;
  r: integer;
  s: dword;
begin
  folderPath := includetrailingbackslash(folderPath);
  s := 0;
  r := findfirst((folderPath + '*.*'), faanyfile, searchRec);
  while (r = 0) do
  begin
    application.processmessages;
    if ((searchRec.attr and fadirectory) <> 0) then
    begin
      if ((searchRec.name <> '.') and (searchRec.name <> '..')) then
        s := s + foldersize(folderPath + searchRec.name);
    end
    else
      S := S + searchRec.FindData.nFileSizeLow;
    r := findnext(searchRec);
  end;
  sysutils.findclose(searchRec);
  result := s;
end; 

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου