extractFileText — Read text from plain text, HTML, and DOCX files.
extractFileText(filename) reads text from a host file and returns a string scalar. This slice supports plain text files with encodings, HTML files through RunMat's extractHTMLText parser, and DOCX files by extracting word/document.xml text.
Syntax
str = extractFileText(filename)
str = extractFileText(filename,Name,Value)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
filename | Any | Yes | — | Path to a text, HTML, or DOCX file. |
NameValue | Any | Variadic | — | Name-value options: Encoding and ExtractionMethod in this slice. |
Returns
| Name | Type | Description |
|---|---|---|
str | StringScalar | Extracted text. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:extractFileText:InvalidInput | Inputs do not match a supported extractFileText form. | extractFileText: invalid input |
RunMat:extractFileText:IOError | The requested file cannot be read. | extractFileText: file read failed |
RunMat:extractFileText:UnsupportedFormat | The requested file type or option requires unsupported extraction infrastructure. | extractFileText: unsupported file type or option |
How extractFileText works
filenamemay be a string scalar, character vector, scalar string array, or 1-by-1 cell containing a text filename.- Plain text files are decoded as UTF-8 by default. The
Encodingname-value option accepts labels supported byencoding_rs, such asUTF-8,windows-1252, andISO-8859-1. - HTML files with extensions
.html,.htm, and.xhtmlare decoded as text and passed toextractHTMLText. - For HTML files,
ExtractionMethodaccepts"tree","article", or"all-text"and follows the existingextractHTMLTextcompatibility behavior. - DOCX files are read as zip archives and text is extracted from
word/document.xml, preserving paragraph breaks and basic tabs/line breaks. - PDF extraction, website/URL fetching, password-protected documents, PDF page selection, legacy binary DOC, and full Microsoft Word layout fidelity remain tracked by the broader Text Analytics compatibility issue.
- Unknown file extensions are treated as plain text files.
GPU memory and residency
extractFileText performs host file IO and text parsing and has no provider kernel.
Examples
Read Plain Text
str = extractFileText("notes.txt")Expected output:
`str` is the file contents as a string scalar.Read HTML Text
str = extractFileText("page.html", "ExtractionMethod", "all-text")Expected output:
`str` contains visible text extracted from the HTML file.Read DOCX Text
str = extractFileText("report.docx")Expected output:
`str` contains the text runs from the DOCX main document part.Using extractFileText with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how extractFileText changes the result.
Run a small extractFileText example, explain the result, then change one input and compare the output.
FAQ
Does extractFileText support PDF files?⌄
Not yet. RunMat rejects PDF-specific forms with a clear error and keeps PDF extraction in the broader Text Analytics queue.
Does extractFileText read websites?⌄
Not in this slice. URL extraction requires web fetching behavior and remains tracked.
Does extractFileText execute on the GPU?⌄
No. It performs host file IO and text parsing.
Related Strings functions
Text Analytics
addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · removeWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding
Transform
append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strip · strjoin · strjust · strrep · strsplit · strtrim · upper
Core
blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native
Search
contains · endsWith · matches · startsWith · strfind
Pattern
digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how extractFileText is executed, line by line, in Rust.
- View the source for extractFileText in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.