[Gambas-user] problem with the File class

Benoit Minisini gambas at ...1...
Fri Mar 4 15:07:02 CET 2005


On Thursday 03 March 2005 19:23, Jean-Francois Perreault wrote:
> Hi,
>
> I'm trying to read files into strings but I have a problem getting the
> size of the opened file
>
> here's the relevant bits
>
> DIM nesdb as File
> OPEN "/home/shodan/nes.txt" FOR READ AS #nesdb
> PRINT nesdb.size
> CLOSE #nesdb
>
> and in the console I get 0
>
> but if I add
> READ #nesdb, sRead , 38238
> TextArea1.Text = sRead
> label1.text = len(sRead)
>
> I get the entire file printed out in textarea1 and 38238 in label1
> I tried setting the third parameter of READ to -1 , the doc says it
> should read until the end of the stream (to the end of file in case of a
> file ?)
>
> but -1 only reads on character , and 0 or unset only read character 2 to
> 40 (probably data-dependant , the doc says the file must have been
> written to with WRITE in this case)
> if I print Stat("/home/shodan/nes.txt").Size
> I get 38238 on the console so I can use that , but I was just wondering
> why the File.Size property wasn't working
>

Actually, Stat() use the File object to store the information about a file. 
So, File.Size can only be use if the File object was created by stat().

I know this is a bit stupid. In the next version, I think Stat() will return 
an object with a Stat-specific class, and won't use the File class anymore. 
File.Size and other Stat-related properties will disappear too.

To know the size of an opened file, use the Lof() function.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list