View Full Version : How to get the size of a file
kornalius
01-08-2007, 08:22 PM
Here is how to get the size of a file in PPL:
func FileSize(filename$)
* f$ = fopen(filename$, "r");
* fseek(f$, 1, SEEK_END);
* filesize$ = ftell(f$) - 1;
* fclose(f$);
* return (filesize$);
end;
Hi Alain,
maybe I don't understand well, but your function "calculates" size of file bigger than it is in fact. The difference is 1. I mean, the fseek(EOF) sets the pointer behind a last valid byte of file and therefore ftell() shows it.
Jerry
kornalius
03-04-2007, 03:13 AM
SEEK_END will position after the end of the last byte of the file? My bad then, so it should be return(filesize$-1) according to what you are saying? I tested the function a little while ago and didn't notice this.
Hi Alain,
I'm sorry for my bad english. I only want to say, that your function and file explorer of PPC give different results. I'll try to add a illustrative picture.[br]../../e107_files/public/1172998439_282_FT2664_size_.jpg[br]
kornalius
03-04-2007, 03:05 PM
Did you test it on the PC as well?
Yes, first I begun on PC with it. The result was identical. I attempt to "penetrate" into your nice PPL also by the help of these examples. I like it.
Jerry
kornalius
03-04-2007, 09:31 PM
Great thanks I will fix the code.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.