FileSizeToStr function
Return to Introduction  Previous page  Next page
Unit
acUtils  

Declaration
function FileSizeToStr(FileName: String;  
                       [Bytes, Kb, Mb: String]): String;  

Description
The FileSizeToStr function returns the string representation of file size. You just need to point the FileName (file name with full path) and function will return the file size in bytes, kilobytes or megabytes (depending on actual size).  
 
tip If the file size is less than 1 kilobyte, the size will be returned in bytes, if less than 1 megabyte, the size will returned in kilobytes, and in megabytes if size is over 1 megabyte.  
 
The number of digits after decimal points depends on file size as well. There is no digits after dicimal point for size in bytes, 1 digit in value in kilobytes and 2 digits in value in megabytes.  
 
For example, return value for file with size of 21090 bytes will be "20.5 KB". If file size is 3867291 bytes, the return value will be "3.68 MB".  
 
iiinfo The Bytes, Kb and Mb is optional parameters used for localization. Use it to override standard English designations of the file size to another language.  
Default values is "bytes", "KB" and "MB".  

Examples
1. FileSizeLabel.Caption := FileSizeToStr(FileName);  
 
2. ListItem.Caption := ExtractFileName(FileName) + '( ' +        FileSizeToStr(FileName, 'bytes''KB''MB') + ')';  
 
3. ListItem.Caption := ExtractFileName(FileName) + '( ' +        FileSizeToStr(FileName, 'bytes''kilobytes''megabytes') + ')';  

See also
ExtractFileSize function.