在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
注意函数返回值类型是Int64,如果文件存在则返回文件大小,否则返回0。 function FileSize(FileName: string): Int64; var sr: TSearchRec; begin if FindFirst(FileName, faAnyFile, sr) = 0 then Result := Int64(sr.FindData.nFileSizeHigh) shl 32 + Int64(sr.FindData.nFileSizeLow) else Result := 0; FindClose(sr); end; 由此可以得到获取文件夹大小的函数如下: function FolderSize(FolderName: string): Int64; var sr: TSearchRec; begin Result := 0; if RightStr(FolderName, 1) <> '\' then FolderName := FolderName + '\'; if FindFirst(FolderName + '*.* ', faAnyFile, sr) = 0 then repeat if (sr.Name <> '.') and (sr.Name <> '..') then begin Result := Result + FileSize(FolderName + sr.Name); if (sr.Attr and faDirectory) <> 0 then Result := Result + FolderSize(FolderName + sr.Name + '\'); end; until FindNext(sr) <> 0; FindClose(sr); end; 参考:
nFileSizeHigh
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论