How to read a text file in the App directory?
|
05-08-2023, 07:17 PM
Post: #1
|
|||
|
|||
How to read a text file in the App directory?
I put a tab delimited file in the app directory, the same place where the logo icon is. I can not find any functions in PPL to read the file. Any help?
Thank you. |
|||
05-08-2023, 07:44 PM
Post: #2
|
|||
|
|||
RE: How to read a text file in the App directory?
Use AFiles("name")
Each HP Prime app can have any number of files associated with it. These files are sent with the app. For example, if there is a file named icon.png associated with the app, then this file is used for the app icon in the Application Library. AFiles returns the list of all these files. AFiles("name") returns the contents of the file with the given name. (user manual, pg. 658 Chapter 29 Programming in HP PPL) |
|||
05-08-2023, 08:39 PM
Post: #3
|
|||
|
|||
RE: How to read a text file in the App directory?
(05-08-2023 07:44 PM)Thomas_Sch Wrote: Use AFiles("name") filevar:=AFiles("FILE.txt") Error: Invalid input The filevar created but contains the number 0 |
|||
05-08-2023, 09:00 PM
(This post was last modified: 05-08-2023 09:04 PM by Thomas_Sch.)
Post: #4
|
|||
|
|||
RE: How to read a text file in the App directory?
(05-08-2023 08:39 PM)mchris Wrote:(05-08-2023 07:44 PM)Thomas_Sch Wrote: Use AFiles("name") Sugestion: Do a search in the forum for "Afiles", e.g. https://www.hpmuseum.org/forum/thread-77...ght=AFiles or https://www.hpmuseum.org/forum/search.ph...order=desc |
|||
05-08-2023, 09:22 PM
Post: #5
|
|||
|
|||
RE: How to read a text file in the App directory?
(05-08-2023 08:39 PM)mchris Wrote: filevar:=AFiles("FILE.txt") What object type is 'filevar' ? Probably needs to be string, but your comment saying "created but contains the number 0" implies its numeric of some type?? --Bob Prosperi |
|||
05-08-2023, 09:34 PM
Post: #6
|
|||
|
|||
RE: How to read a text file in the App directory?
You cannot read a text file with AFiles, as AFiles is expecting the file to contain HP Prime objects such as Lists, Strings, Matrix etc... and not raw text characters.
Instead you can use AFilesB to access the text file at byte level. See some explanations here. |
|||
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); |
|||
05-09-2023, 06:42 AM
Post: #8
|
|||
|
|||
RE: How to read a text file in the App directory?
Bonjour,
Une autre possibilité que j'ai déjà utilisé est de copier le contenu du fichier texte dans une note de l'application depuis le logiciel de connectivité sur le PC. Ensuite vous pouvez récupérer le contenu de cette note donc le texte avec ANote sous forme de chaîne. Je ne connais pas la limite mais j'ai déjà fais cela avec des fichiers d'une centaine de Ko. Si ça peut aider. Hello, Another possibility I have used is to copy the contents of the text file into a note in the application from the connectivity software on the PC. Then you can retrieve the content of this note so the text with ANote as a string. I don't know the limit but I have done this with files of a hundred KB. If it helps. Sorry for my english |
|||
05-09-2023, 09:56 AM
Post: #9
|
|||
|
|||
RE: How to read a text file in the App directory?
(05-08-2023 07:44 PM)Thomas_Sch Wrote: Use AFiles("name") Thnaks for the reply. You mentioned user manual pg. 658. Where can I get this? My user guide doesn't have too many pages. It's already in Index by page 640. |
|||
05-09-2023, 12:18 PM
Post: #10
|
|||
|
|||
RE: How to read a text file in the App directory?
--Bob Prosperi |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)