Vybe Documentation
Vybe Main page
File I/O Functions
Vybe provides two sets of file operations: modern System.IO-style functions and legacy VB6-style statements.
System.IO.File (Standard)
| Function | Syntax | Description |
|---|---|---|
| File.ReadAllText | File.ReadAllText(path) |
Returns the entire content of a text file. |
| File.WriteAllText | File.WriteAllText(path, text) |
Writes text to a file, overwriting existing content. |
| File.AppendAllText | File.AppendAllText(path, text) |
Appends text to a file. |
| File.Exists | File.Exists(path) |
Returns True if the specified file exists. |
| File.Delete | File.Delete(path) |
Deletes the specified file. |
| File.Copy | File.Copy(src, dst) |
Copies a file to a new location. |
| File.Move | File.Move(src, dst) |
Moves a file to a new location. |
| File.ReadAllLines | File.ReadAllLines(path) |
Reads all lines from a file into an array. |
Path Class
The System.IO.Path class provides methods for manipulating path strings in a cross-platform manner.
| Method | Description |
|---|---|
| GetFileName | Returns the file name and extension of the specified path string. |
| GetFileNameWithoutExtension | Returns the file name without the extension. |
| GetExtension | Returns the extension of the specified path string. |
| GetDirectoryName | Returns the directory information for the specified path string. |
| GetFullPath | Returns the absolute path for the specified path string. |
| GetTempPath | Returns the path of the current user's temporary folder. |
| HasExtension | Returns a value indicating whether a path includes a file name extension. |
| IsPathRooted | Returns a value indicating whether the specified path string contains a root. |
| ChangeExtension | Changes the extension of a path string. |
Stream I/O
For more granular control over file reading and writing, use the StreamReader and StreamWriter classes.
StreamWriter
Used for writing text to a file.
- New(path): Opens a file for writing.
- WriteLine(text): Writes a line of text followed by a line terminator.
- Write(text): Writes text without a line terminator.
- Close(): Closes the writer and releases resources.
StreamReader
Used for reading text from a file.
- New(path): Opens a file for reading.
- ReadLine(): Reads a line of characters and returns it as a string.
- ReadToEnd(): Reads all characters from the current position to the end.
- EndOfStream: Property that returns True if the end of the stream has been reached.
- Close(): Closes the reader.
Examples
Modern System.IO
Dim configPath As String = "config.txt"
If File.Exists(configPath) Then
Dim content As String = File.ReadAllText(configPath)
MsgBox("Config: " & content)
Else
File.WriteAllText(configPath, "Version=1.0")
End If
Legacy VB6 Style
Dim fNum As Integer = FreeFile()
Open "log.txt" For Append As #fNum
Print #fNum, "Log entry at " & Now()
Close #fNum
System.IO.Directory
| Function | Syntax | Description |
|---|---|---|
| Directory.Exists | Directory.Exists(path) |
Returns True if the specified directory exists. |
| Directory.CreateDirectory | Directory.CreateDirectory(path) |
Creates all directories in the specified path. |
| Directory.Delete | Directory.Delete(path) |
Deletes the specified directory and its contents. |
| Directory.GetFiles | Directory.GetFiles(path) |
Returns an array of file names in a directory. |
| Directory.GetDirectories | Directory.GetDirectories(path) |
Returns an array of directory names. |
| Directory.GetCurrentDirectory | Directory.GetCurrentDirectory() |
Returns the current working directory. |
VB6 Legacy Statements
| Statement | Syntax | Description |
|---|---|---|
| Open | Open path For Mode As #id |
Opens a file for I/O. |
| Close | Close [#id] |
Closes one or more open files. |
Print #id, [expressions] |
Writes formatted data to a file. | |
| Write | Write #id, [expressions] |
Writes data to a file in a compact format. |
| Input | Input #id, [variables] |
Reads data from an open file. |
| Dir | Dir([pattern]) |
Returns the first file name matching the pattern. |
| Kill | Kill(pathname) |
Deletes a file. |
| FileCopy | FileCopy(src, dst) |
Copies a file. |
| MkDir | MkDir(path) |
Creates a directory. |
| RmDir | RmDir(path) |
Removes a directory. |
| ChDir | ChDir(path) |
Changes the current directory. |
| CurDir | CurDir([drive]) |
Returns the current path. |
| FileLen | FileLen(path) |
Returns the length of a file in bytes. |
| FileDateTime | FileDateTime(path) |
Returns the last modified date/time of a file. |
| GetAttr | GetAttr(path) |
Returns the attributes of a file or directory. |
| SetAttr | SetAttr(path, attr) |
Sets the attributes of a file. |
| FreeFile | FreeFile() |
Returns the next available file number. |
File Handle Info
- EOF(id): Returns True if the end of file has been reached.
- LOF(id): Returns the length of an open file in bytes.
- LOC(id): Returns the current position within an open file.