1 //------------------------------------------------------------------------- 2 3 #include <vcl.h> 4 #pragma hdrstop 5 6 #include "Unit1.h" 7 //--------------------------------------------------------------------------- 8 #pragma package(smart_init) 9 #pragma resource "*.dfm" 10 TForm1 *Form1; 11 //--------------------------------------------------------------------------- 12 __fastcall TForm1::TForm1(TComponent* Owner) 13 : TForm(Owner) 14 { 15 16 } 17 long FileSizeByName(String Fn){ 18 //this function returns the size of any given file in bytes 19 20 TSearchRec SearchRec; 21 int i; 22 23 try { 24 i = FindFirst(Fn, faAnyFile, SearchRec); 25 if( i == 0){ 26 return SearchRec.Size; 27 } 28 else{ 29 return -1; 30 } 31 } 32 catch(Exception &exception){ 33 FindClose(SearchRec); 34 } 35 } 36 37 //--------------------------------------------------------------------------- 38 39 void __fastcall TForm1::Button1Click(TObject *Sender) 40 { 41 long i; 42 i = FileSizeByName("C:\\winnt\\notepad.exe"); 43 String sI =i; 44 ShowMessage("The size of the file is: "+ sI +" bytes."); 45 } 46 //---------------------------------------------------------------------------