Page 1 of 1

FileStr()

Posted: Wed Apr 01, 2009 11:02 am
by xProgrammer
Hi all

I have just had to write some code to run on a Windows box. I wrote the code on a linux machine where it ran fine and then compiled under Windows. It compiled and ran but errored out. The problem turned out to be theFileStr() function which on Linux seemed to cope with fair sized files (certainly up to 160K) whereas under Windows (XP) it seemed to have a limit (from memory about 30K).

I programmed around this using FOpen(), FRead() and a pre-allocated buffer, but I was wondering if anyone else had struck this problem?

Regards

Doug

Re: StrFile()

Posted: Wed Apr 01, 2009 11:39 am
by Antonio Linares
Hi Doug,

Nice to see you again here :-)

What parameters are you using to call StrFile() ?

Re: StrFile()

Posted: Wed Apr 01, 2009 11:40 am
by Antonio Linares
You can also use MemoWrit() to save a string to a file.

Its easier than using FCreate(), etc.

Re: FileStr()

Posted: Wed Apr 01, 2009 11:55 am
by xProgrammer
OOps! I meant FileStr() NOT StrFile()!

I was just calling as follows:

FileData := FileStr( FileName )

That is I omitted parameter 2 (nBytes) so it should read the entire file (and does so under Linux) but under Windows seems to only read the first 30K or so.

Sorry about mixing up FileStr() and StrFile().

Regards

Doug

Re: FileStr()

Posted: Wed Apr 01, 2009 12:23 pm
by Enrico Maria Giordano
This sample works fine here:

Code: Select all

FUNCTION MAIN()

    LOCAL cBuf := FILESTR( "TEST.EXE" )

    ? LEN( cBuf )

    INKEY( 0 )

    RETURN NIL
EMG

Re: FileStr()

Posted: Wed Apr 01, 2009 12:44 pm
by Antonio Linares
I guess that code is equivalent to:

local cText := MemoRead( "test.exe" ) :-)