Author: Tomas Rutkauskas
How I can convert bytes to file size in KB/MB like in windows explorer
Answer:
1 function FileSizeStr(Size: LongInt): string;
2 begin3 if Size < 1000 then4 Result := IntToStr(Size) + ' B'
5 elseif Size < 102400 then6 Result := IntToStr((Size + 1023) shr 10) + ' KB'
7 else8 Result := IntToStr((Size + 1048575) shr 20) + ' MB';
9 end;