Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File size

Status
Not open for further replies.

MAM

Programmer
Sep 12, 2000
5
0
0
US
How can I obtain the size of a file without opening the file? I understand that the function FileSize will return the size of the file in bytes; however, to use this function, the file must be open. Is there another function out there that will return the file size without requiring the file to be open? [sig][/sig]
 
NO WAY [sig]<p>Button1<br><a href=mailto:button1@263.net>button1@263.net</a><br>[/sig]
 
There is a way (minimum one way :)).
Use the FindFirst/FindNext/FindClose to find the file, and see the Size field in the result (TSearchRec type).

Good luck. Bye, Otto. [sig][/sig]
 
This is a window api call
The GetFileSize function retrieves the size, in bytes, of the specified file.

DWORD GetFileSize(

HANDLE hFile, // handle of file to get size of
LPDWORD lpFileSizeHigh // address of high-order word for file size
);


Parameters

hFile

Specifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.

lpFileSizeHigh

Points to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.



Return Values [sig][/sig]
 
The following code could be put into a function to return you the filesize of a file.

var
SearchRec: TSearchRec;
begin
if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then
Result := SearchRec.Size
else Result := -1;

//close the searchrec
FindClose(SearchRec);
end;

Hope this helps.

Brett Parkhurst
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top