Post Reply 
How to read a text file in the App directory?
05-09-2023, 03:33 AM
Post: #7
RE: How to read a text file in the App directory?
Here is some sample code from one of my apps, cur_name is the name of the text file. Keep in mind that lists are limited to 10000 length, so if reading a file longer than that many bytes, you have to iterate to get the contents.

LOCAL cur_name,fsize,fiter,fcontent,fstring:="",j;

Code:
                  fsize:=AFilesB(cur_name);
                  IF fsize>10000 THEN
                    fiter:=IP(fsize/10000);
                    FOR j FROM 1 TO fiter DO
                      fcontent:=AFilesB(cur_name,(j-1)*10000,10000);
                      fcontent:=CHAR(fcontent);
                      fstring:=fstring+fcontent;
                    END;
                    IF FP(fsize/10000) THEN
                      fcontent:=AFilesB(cur_name,fiter*10000,fsize-(fiter*10000));
                      fcontent:=CHAR(fcontent);
                      fstring:=fstring+fcontent;
                    END;
                    fcontent:=fstring;
                  ELSE
                    fcontent:=AFilesB(cur_name,0,fsize);
                    fcontent:=CHAR(fcontent);
                  END;
                  fcontent:=REPLACE(fcontent,CHAR(13),CHAR(10));
                  fcontent:=REPLACE(fcontent,CHAR(10)+CHAR(10),CHAR(10));
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How to read a text file in the App directory? - Jacob Wall - 05-09-2023 03:33 AM



User(s) browsing this thread: 2 Guest(s)