i want to get size of a file (DOS/LINUX), I use fopen to open file but i dont know how to obtain it's size.
Posted on 2003-12-10 16:05:14 by AceEmbler
I don't know anything about linux programming but maybe this filesize function from the HLA standard library will help.

 

#if( os.linux )

procedure fsize_handle( handle:dword ); @nodisplay;
var
fstat : linux.stat_t;

begin fsize_handle;

linux.fstat( handle, fstat );
if( eax = -1 ) then

raise( ex.FileReadError );

endif;
mov( fstat.st_size, eax );

end fsize_handle;
Posted on 2003-12-10 16:12:07 by Odyssey
The stat function is a possibility, a more general way is seeking to the end of the file with fseek, then reading the file pointer with ftell.

Thomas
P.S. What was this doing in the crusades? Moved it to the heap :).
Posted on 2003-12-10 16:22:43 by Thomas
fseek() with SEEK_END + ftell()?

ah Thomas beat me :D
Posted on 2003-12-10 16:22:49 by Hiroshimator


Thomas
P.S. What was this doing in the crusades? Moved it to the heap :).


thx all


you know it was about C and stuff......

BTW Hiro can you add this emoticon to this board ???
Posted on 2003-12-10 16:30:55 by AceEmbler
well, yes if you can tell me what it means :)


BTw have you seen Samurai Deeper Kyo? it's great
Posted on 2003-12-10 16:49:04 by Hiroshimator
It's not that easy to explain but i will try.

So you can use it when someone say or do something stupid. When you say something idiotically obvious and make big case about this.
damn it is hard to explain


Yep i have seen Samurai deeper kyo and it was nice anime. But you can find more interesting animes out there.


about this emoticon:
for example we are on a anime board and someone tell us that "Akira" is stupid and boring anime.

we can answer (or dont answer at all to such a question :tongue: )

Becouse we just cant measure "Akira" just like that.



:alright: (that's a pity its not the luckyest example :cool: )



But returning to my previous question.

Can you tell me why fseek is bigger than ftell ???
Posted on 2003-12-10 17:14:53 by AceEmbler
bigger?

you should do something like

fseek(pStream,0,SEEK_END);
filesize = ftell(pStream);

then filesize will contain the size in bytes of the file
Posted on 2003-12-10 18:09:20 by Hiroshimator
fseek(fd,FEnd,SEEK_END);
FBegin=ftell(fd);
Err=FEnd - FBegin;
printf("size %d\n",Err);

i made something like this and the size was -87 (my file size is 87)
Posted on 2003-12-10 18:41:53 by AceEmbler
well FEnd has to be 0 for that to work

0 - 87.... :)
Posted on 2003-12-10 18:43:22 by Hiroshimator
The file size can be different though, if you opened it in ascii mode. Then CR/LFs might be translated into something else, so that fseek+ftell will give you a different value than the raw filesize that stat gives you.

Thomas
Posted on 2003-12-11 02:53:04 by Thomas
what is CR and LFs.


BTW Hiro what about this emoticon ??
Posted on 2003-12-11 07:26:20 by AceEmbler
Carriage return line feeds. windows makes use of CRLF while *nix makes use of LF. IIRC mac makes use of CR and thus windows is the cross breed between *nix and mac when it comes to pressing the enter button.
Posted on 2003-12-11 08:03:09 by roticv
when you say ASCI mode it's the same as text mode yes ??
Posted on 2003-12-11 08:25:25 by AceEmbler
Yes :)

Thomas
Posted on 2003-12-11 08:31:01 by Thomas
damn damn that C.

i have got a problem its probably about this asci mode you are talking about. I try to take bytes(characters) from:
My file contains such a chars. (bytes(dec))

93 13 10 91

when i take bytes after bytes

first is 93 second is 10 and third is 91
how can i read this thing properly ??
Posted on 2003-12-11 10:20:37 by AceEmbler
13=CR 10=LF. Read in binary mode and not ascii.
Posted on 2003-12-11 11:33:59 by roticv
I've always used:
filelength(fileno(file))

But I guess this isn't portable :rolleyes:
Posted on 2003-12-11 13:51:09 by gliptic