_READFILE$

From QB64 Phoenix Edition Wiki
Revision as of 18:28, 13 February 2024 by RhoSigma (talk | contribs) (Created page with "{{DISPLAYTITLE: _READFILE$}} The '''_READFILE$''' function returns the complete contents of a file in a single string, but without the usual overhead. It does OPEN, GET and CLOSE the file in one run. {{PageSyntax}} : {{Parameter|content$}} = _READFILE$({{Parameter|fileSpec$}}) {{PageParameters}} * {{Parameter|content$}} is the entire file contents returned as STRING. Maybe empty, if the file specified was an empty file, or if the program is contin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The _READFILE$ function returns the complete contents of a file in a single string, but without the usual overhead. It does OPEN, GET and CLOSE the file in one run.


Syntax

content$ = _READFILE$(fileSpec$)


Parameters

  • content$ is the entire file contents returned as STRING. Maybe empty, if the file specified was an empty file, or if the program is continued from an file related ERROR.
  • fileSpec$ is the name of the file to read as literal or variable STRING, if required inclusive a full or relative path.


Description

  • Sometimes it's required or at least useful to have the whole contents of a file in a single string for further processing, e.g. to use INSTR on it or similar task.
  • In earlier versions of QB64(PE) you had to implement that loading process manually all the time or create a reusable custom FUNCTION for it.
  • Now _READFILE will simplify this, it's mainly a convenience function to wrap the following code sequence in one handy function:
fh = FREEFILE
OPEN fileSpec$ FOR BINARY AS #fh
content$ = SPACE$(LOF(fh))
GET #fh, , content$
CLOSE #fh


Availability


Examples

Example
Showing how the Crc-32 checksum can detect differences in two strings.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link