الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف يمكن معرفة جحم الملف ؟؟

بدأه أحمد_ليبيا في 30 مارس 2008 · 6 رد · 711 مشاهدة · في لغة Delphi
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

..

- اذا كان لدي ملف في القرص D ، وقمت باستعراضع باستخدام المكون (OpenDialog)

- كيف يمكن معرفة جحم الملف الذي قمت باستعراضه

moslimbag8.gif

------

saaid.jpg

#2
procedure TForm1.Button1Click(Sender: TObject);								
var																			
  F: TFileStream;															  
begin																		  
  if OpenPictureDialog1.Execute then										   
  begin																		
	F := TFileStream.Create(OpenPictureDialog1.FileName, fmOpenRead);		  
	Caption := IntToStr(F.Size);											   
  end;																		 
end;

تم تعديل هذه المشاركة بواسطة الأرنب الأبيض في 30 مارس 2008 في 09:48

#3

مشكووور اخوي محمد ... نتج الكود معيييييي

moslimbag8.gif

------

saaid.jpg

#4
محمد144 كتب:
procedure TForm1.Button1Click(Sender: TObject);								
var																			
  F: TFileStream;															  
begin																		  
  if OpenPictureDialog1.Execute then										   
  begin																		
	F := TFileStream.Create(OpenPictureDialog1.FileName, fmOpenRead);		  
	Caption := IntToStr(F.Size);											   
  end;																		 
end;

ليس هناك داعي لتحميل الملف في filestream لكي تعرف حجمه, فذلك سوف يستنفذ موارد النظام..

var
  myFile : file of word;
begin
  AssignFile(myFile, 'Test.cus');
  ShowMessage('File size = '+IntToStr(FileSize(myFile)));
  // Close the file
  CloseFile(myFile);
end;

رب اجعلني مقيم الصلاة ومن ذريتي ربنا وتقبل دعاء.

لا تنسى: "العقل مثل العضلة كلما استخدمته أكثر كلما ازدادت قوته"

#5

السلام عليكم اخوي

..

الكود ما يشتغل ..........!

moslimbag8.gif

------

saaid.jpg

#6

هي أربع طرق

find the size of a file

Author: JD McDonnell 
Homepage: http://www.greaterthanzen.com 

Category: Files


function Get_File_Size1(sFileToExamine: string; bInKBytes: Boolean): string;
{
 for some reason both methods of finding file size return
 a filesize that is slightly larger than what Windows File
 Explorer reports
}
var
  FileHandle: THandle;
  FileSize: LongWord;
  d1: Double;
  i1: Int64;
begin
  //a- Get file size
  FileHandle := CreateFile(PChar(sFileToExamine),
	GENERIC_READ,
	0, {exclusive}
	nil, {security}
	OPEN_EXISTING,
	FILE_ATTRIBUTE_NORMAL,
	0);
  FileSize   := GetFileSize(FileHandle, nil);
  Result	 := IntToStr(FileSize);
  CloseHandle(FileHandle);
  //a- optionally report back in Kbytes
  if bInKbytes = True then
  begin
	if Length(Result) > 3 then
	begin
	  Insert('.', Result, Length(Result) - 2);
	  d1	 := StrToFloat(Result);
	  Result := IntToStr(round(d1)) + 'KB';
	end
	else
	  Result := '1KB';
  end;
end;

{******************************************************************************
Thanks to Advanced Delphi Systems here's another method which works just as
well returning the same results
*******************************************************************************}
function Get_File_Size2(sFileToExamine: string; bInKBytes: Boolean): string;
var
  SearchRec: TSearchRec;
  sgPath: string;
  inRetval, I1: Integer;
begin
  sgPath := ExpandFileName(sFileToExamine);
  try
	inRetval := FindFirst(ExpandFileName(sFileToExamine), faAnyFile, SearchRec);
	if inRetval = 0 then
	  I1 := SearchRec.Size
	else
	  I1 := -1;
  finally
	SysUtils.FindClose(SearchRec);
  end;
  Result := IntToStr(I1);
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
	label1.Caption := Get_File_Size(Opendialog1.FileName, True);
end;

{*******************************************************************************
}

function Get_File_Size3(const FileName: string): TULargeInteger;
// by nico
var
  Find: THandle;
  Data: TWin32FindData;
begin
  Result.QuadPart := -1;
  Find := FindFirstFile(PChar(FileName), Data);
  if (Find <> INVALID_HANDLE_VALUE) then
  begin
	Result.LowPart  := Data.nFileSizeLow;
	Result.HighPart := Data.nFileSizeHigh;
	Windows.FindClose(Find);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if (OpenDialog1.Execute) then
	ShowMessage(IntToStr(Get_File_Size3(OpenDialog1.FileName).QuadPart));
end;

{*******************************************************************************
}

function Get_File_Size4(const S: string): Int64;
var
  FD: TWin32FindData;
  FH: THandle;
begin
  FH := FindFirstFile(PChar(S), FD);
  if FH = INVALID_HANDLE_VALUE then Result := 0
  else
	try
	  Result := FD.nFileSizeHigh;
	  Result := Result shl 32;
	  Result := Result + FD.nFileSizeLow;
	finally
	  CloseHandle(FH);
	end;
end;
#7

جرب الاكواد ولكن ما مشى الحال ... ممكن السورس كود

moslimbag8.gif

------

saaid.jpg

مواضيع مشابهة