Breaking News
Loading...
Sunday, August 18, 2013



Get FileSize Borland Delphi 7 1 300x161 When working with files and folders from a Borland Delphi 7, application you sometimes need to know what is the size of a file (in bytes or non formating).


Get File Size

The FileSize function returns the size of a file in bytes, -1 if the file was not found.


The FileSize function as follows:



//Returns file size in bytes or -1 if not found.
function FileSize(fileName : wideString) : Int64;
var
sr : TSearchRec;
begin
if FindFirst(fileName, faAnyFile, sr ) = 0 then
result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow)
else
result := -1;

FindClose(sr) ;
end;

When working with files from Borland Delphi 7 you might want to display the size of a file to the user in a Explorer-like format where the file size is not displayed in bytes – but the display depends on the size of the actual file.


To most users “21720″ is confusing – where “21.21 KB” is much more user friendly.


Format Byte Size to String

A custom Delphi function, FormatByteSize, converts a byte value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.


Format Byte Size to String function as follows:

0 comments:

Post a Comment

 

Receive All Free Updates Via Facebook.