File class
A file inside the IDE’s virtual file system. Extends FileSystemItem with content accessors — raw bytes via Data / DataLen, a decoded text view via Text, a text-with-options accessor via ReadText, plus an IsDirty flag indicating unsaved changes.
A File also inherits the universal FileSystemItem members — Name, Path, Type, Parent. The Type value tells the addin what encoding the file is in and whether the text accessors are applicable; see FileSystemItemType for the list.
' Read every source file's text:
Private Sub WalkAllFiles(ByVal folder As Folder)
Dim item As FileSystemItem
For Each item In folder
If TypeOf item Is Folder Then
WalkAllFiles item
Else
Dim file As File = item
If file.Type <> FileOTHER Then
ProcessText file.Path, file.ReadText(ReadTextFlags.CommentsToWhitespace)
End If
End If
Next
End Sub
Note
File content is currently read-only from the addin’s perspective. The interface declares Property Let accessors for Data and Text but they are tagged [Unimplemented]. Use Editor.Save on an active editor pane to persist text changes made through that pane, or CodeEditor.Text / CodeEditor.SelectedText for in-editor edits.
Properties
Data
The raw on-disk bytes of the file. Read returns a Byte() of the current content. The Property Let form is declared but marked [Unimplemented] — writes are not currently supported.
Syntax: file.Data As Byte()
DataLen
The length in bytes of the current content — equivalent to UBound(file.Data) + 1 but without copying the array. LongLong, read-only. Useful for size displays and quick file-size comparisons.
IsDirty
True if the file has unsaved changes in the IDE. Boolean, read-only.
Text
The file’s content decoded as a String, with the appropriate UTF-16 conversion for the underlying encoding (FileTWIN → UTF-8 → UTF-16; FileBAS / FileCLS → System-ANSI → UTF-16; FileVIRTUALDOC / FileUIDESIGNER / FileJSON → UTF-8 → UTF-16). Calling on a FileOTHER is not supported.
Read returns the decoded text. The Property Let form is declared but marked [Unimplemented] — writes are not currently supported.
Syntax: file.Text As String
Methods
ReadText
A text-with-options accessor — the Text view, but with optional transforms applied. Currently the only option strips comments and replaces them with whitespace; future versions may add more.
Syntax: file.ReadText( Options ) As String
- Options
- required A ReadTextFlags value. Pass
0for raw text equivalent to reading Text; pass CommentsToWhitespace to mask out comments while preserving line and column positions of every non-comment character.
Valid on every text file kind (FileTWIN, FileBAS, FileCLS, FileVIRTUALDOC, FileUIDESIGNER, FileJSON); calling on a FileOTHER is not supported.
The line and column structure of the returned text matches the original file — CommentsToWhitespace only blanks the comment characters, never moves the surrounding code. That makes the option suitable for indexers / search tools that need both “find non-comment occurrences” and “report the position in the original file”.
ReadTextFlags
The option flags consumed by ReadText. A [Flags]-tagged enum — values can be Or‘ed in future versions.
| Constant | Value | Description |
|---|---|---|
| CommentsToWhitespace | 1 | Replace every byte that is part of a comment with a space. Line / column positions of every non-comment character are preserved. |