![]() |
|
حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - نسخة قابلة للطباعة +- delphi4arab منتديات دلفي للعرب (https://delphi4arab.net/forum) +-- قسم : منتديات دلفي التقنية (https://delphi4arab.net/forum/forumdisplay.php?fid=6) +--- قسم : دلفي والتعامل مع الملفات (https://delphi4arab.net/forum/forumdisplay.php?fid=22) +--- الموضوع : حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) (/showthread.php?tid=2819) |
حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - Lam.Abdeldjalil - 21-02-2011 السلام عليكم و رحمة الله توجد عدة طرق لحساب حجم الملفات نقدم إثنان منهما : الأولى : مايميزها أنها تحسب الحجم حتى بالتيرابايت TB ( لم أجربها * لا أملك ملف بها الحجم ) كود : function FileSizeStr ( filename: string ): string;
const
K = Int64(1024); // KB
M = K * K; // MB
G = K * M; // GB
T = K * G; // TB
var
size: Int64;
handle: integer;
begin
handle := FileOpen(filename, fmOpenRead);
if handle = -1 then
result := 'Unable to open file ' + filename
else try
size := FileSeek ( handle, Int64(0), 2 );
if size < K then result := Format ( '%d bytes', [size] )
else if size < M then result := Format ( '%f KB', [size / K] )
else if size < G then result := Format ( '%f MB', [size / M] )
else if size < T then result := Format ( '%f GB', [size / G] )
else result := Format ( '%f TB', [size / T] );
finally
FileClose ( handle );
end;
end;كود : ShowMessage('File Size '+ FileSizeStr('debian-6.0.0-i386-DVD-1.iso'));كود : function FileSizeStr2 ( filename: string ): string;
var
f : File of byte;
fs : cardinal;
const
K = Int64(1024); // KB
M = K * K; // MB
G = K * M; // GB
T = K * G; // TB
begin
AssignFile(f,filename);
try
Reset(f);
fs := system.FileSize(f);
if fs < K then result := Format ( '%d bytes', [fs] )
else if fs < M then result := Format ( '%f KB', [fs / K] )
else if fs < G then result := Format ( '%f MB', [fs / M] )
else if fs < T then result := Format ( '%f GB', [fs / G] )
else result := Format ( '%f TB', [fs / T] );
finally
CloseFile(f);
end;حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - kachwahed - 22-02-2011 وعليكم السلام ورحمة الله وبركاته فكرة جميلة ![]() هناك توابع API Windows جاهزة لحساب حجم الملفات بـ KB أو B كود : (* -----------------------------------------
Use this function to display the "69.1 Kb"
instead 70846, "1.61 Mb" instead 1697109,
etc...
----------------------------------------- *)
// API declarations
function StrFormatByteSize(dw: DWORD; szBuf: PChar; uiBufSize: UINT): PChar; stdcall; external 'shlwapi.dll' name 'StrFormatByteSizeA';
function StrFormatKBSize(qdw: LONGLONG; szBuf: PChar; uiBufSize: UINT): PChar; stdcall; external 'shlwapi.dll' name 'StrFormatKBSizeA';
// ---------
// Code
// ---------
// ------------------------------------------------------- //
function Formatted_FileSize(SizeInBytes: Cardinal) : String;
var
arrSize: array[0..255] of Char;
begin
// same formating like in statusbar of Explorer
StrFormatByteSize(SizeInByte, arrSize, Length(arrSize) - 1);
Result := Trim(arrSize);
end;
// ------------------------------------------------------- //
function KB_Formatted_FileSize(SizeInKB: Cardinal) : String;
var
arrSize: array[0..255] of Char;
begin
// same formating like in Size column of Explorer in detailed mode
StrFormatKBSize(SizeInKB, arrSize, Length(arrSize)-1);
Result := Trim(arrSize);
end;
// ------------------------------------------------------- //لم أجربه الآن، أظن كان به خلل صغير بالتوفيق. حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - you_per7 - 02-06-2014 شكرا جزيلا.... حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - norbik - 26-02-2015 ماهي المكونات التي يجب وضعها وبارك الله فيكم حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - محمد عبد العزيز - 01-03-2015 norbik كتب :ماهي المكونات التي يجب وضعهاهذه function للحساب والنتيجة نص يمكنك اضهاره باي مكون تشاء حساب حجم الملفات بـ ( Byte / KB /MB /GB / TB) - hatem-ghouthi - 03-03-2015 شكرا اخي . وبارك الله فيك . |