Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / Delphi - Get File Size in Bytes (just cant find way how!)

Author
Message
Sergey K
21
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 28th Jan 2006 23:29
hey all, i've been searching for a simple thing in delphi to find a local file size and i found a lot of different functons/commands but actually non of them are truly getting the size of the file in bytes.
i've tryed GetFileSize and GetSize commands.. they are not good.. for my
or are they?

empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 29th Jan 2006 00:08
GetFileSize is not a "native" Delphi function, but part of the WinAPI. You can use it too, but it's a bit more complicated. It's easier to use the function called FileSize.

Sergey K
21
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 29th Jan 2006 00:48
i've tryed it, but its not getting the right size in bytes..
i have tryed:

Showmessage(IntToStr(GetFileSize(Handle,pchar('filename.txt')));

the oreginal size that windows shows me is: 1323640 bytes
and the function returns me: 4294967295

RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 29th Jan 2006 02:12 Edited at: 29th Jan 2006 02:15
try something like:



Hope this helps, been a while since I've used Delphi.
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 29th Jan 2006 02:25
Quote: "i've tryed it, but its not getting the right size in bytes..
i have tryed:

Showmessage(IntToStr(GetFileSize(Handle,pchar('filename.txt')));

the oreginal size that windows shows me is: 1323640 bytes
and the function returns me: 4294967295"

What did you pass as "handle" ?
You need to open a file first (with CreateFile).

RalphY solution (that uses FileSize instead of GetFileSize) seems to be fine.

Sergey K
21
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 29th Jan 2006 08:21 Edited at: 29th Jan 2006 08:22
@RalphY: tryed that one, but it getting me the size in KBytes

Quote: "What did you pass as "handle" ?"

err.. should it be something?
i just used var handle:THandle should i do somethingh else with it?
and i remember i used the CreateFile commands and then using it to get the handle and all. but its always returned me -1

empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 29th Jan 2006 13:43 Edited at: 29th Jan 2006 13:45
Quote: "@RalphY: tryed that one, but it getting me the size in KBytes"

Well, here it returns the size in bytes for me.


Quote: "err.. should it be something?
i just used var handle:THandle should i do somethingh else with it?
and i remember i used the CreateFile commands and then using it to get the handle and all. but its always returned me -1"

Well you need to fill that handle with a proper value.



Sergey K
21
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 29th Jan 2006 14:26
thx empty, but i found some other weird way
im not sure how they did that, but its working..

RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 29th Jan 2006 16:33
Quote: "tryed that one, but it getting me the size in KBytes"


Could you not have just converted it into bytes?

[KBytes]*1024 = [Bytes]
Sergey K
21
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 29th Jan 2006 18:32
@RalphY: it wont be exact the same size though

Login to post a reply

Server time is: 2025-05-28 03:56:01
Your offset time is: 2025-05-28 03:56:01