Get folder size
This function tells you how many bytes a folder, with all subfolders and contained files is taking.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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; |