6.1.2.5 FileSystem
Note
This section describes the implementation of MS-VBAL §6.1.2.5 FileSystem.
The FileSystem module is represented in the language core by the interface
IStdFileSystemModule, and implemented by RDCore.Runtime.StdLib.StdFileSystem.
What a member does to the machine - a directory listed, a file copied or deleted, the current directory changed - goes through the session's IFileChannels, the one seam every file statement goes through (RD-VBAL §5.4.5): the channels know which files are open, which most of these members ask, and the seam is what an administrator restricts and a test fakes. What the specification leaves to the implementation, and the errors it does not name, are MS-VBA's, recorded in Excel; where MS-VBA does other than the specification says, RD-VBA does what MS-VBA does, and the notes below say so.
Current directory
MS-VBAL leaves the current directory a program starts in to the host: CurDir gives the path of an implementation-defined current drive
(MS-VBAL §6.1.2.5.1.1 CurDir),
Open combines a relative path with the current drive and directory in an implementation-defined manner
(MS-VBAL §5.4.5.1 Open Statement), and the host maps file I/O to the
platform's storage (MS-VBAL §2.7.3). In RD-VBA:
- A session composed for a workspace starts in the workspace root, the folder of its
.rdproj, when the workspace loads and each time the project is reloaded. A relative path inOpen,DirorKillis a file of the workspace. ChDirandChDrivemove it.Endleaves it where the program put it.- The interactive shell started without a workspace runs in a temporary one, and its session stays in the folder the environment host was started in.
Path separators
A path given to a file statement or a FileSystem member may separate its folders with \ on every platform (RD-VBA addition). Where the file system's
separator is / (Linux, macOS), each \ in the path is read as /: Open "Data\in.txt" opens Data/in.txt in the current directory. On Windows a path
is used as given. CurDir gives the path as the file system spells it, with / on Linux and macOS, and Dir gives names with no directory part.
When the current directory is deleted (Linux and macOS allow it), CurDir and a relative path given to a file statement or a FileSystem
member raise error 76 (RD-VBA addition). A full path still works.
Note
On Linux and macOS, a file or folder whose name contains \ cannot be reached through the VBA file functions.
6.1.2.5.1 Public Functions
Note
This section describes the implementation of MS-VBAL §6.1.2.5.1 Public Functions.
| § | Member | Notes |
|---|---|---|
| 6.1.2.5.1.1 | CurDir/CurDir$ | A drive is its first letter: error 68 for a letter that is no drive, 5 for a drive that is no letter. The format of a drive is implementation-defined: a letter, as on Windows - a file system that has none (Linux) has no drive a letter names. |
| 6.1.2.5.1.2 | Dir | Names with no directory part, spelled as the file system spells them, matched whatever their case and given in the order of their upper-case spelling - the directory the pattern is in being found as the file system finds it, by its case on one whose names are (Linux) - . and .. first, with vbDirectory, which matches files too. A hidden or a system file only with vbHidden or vbSystem. A pattern ending in a separator is what is in the directory; what matches nothing, a directory that does not exist included, is a zero-length String. With no pattern, the next match, then a zero-length String, then error 5. |
| 6.1.2.5.1.3 | EOF | Random and Binary: True once the last Get could not read an entire record - reading the last byte is not enough. Error 52 for a file number that is not open. |
| 6.1.2.5.1.4 | FileAttr | Only ReturnType 1: 2, the handle, is error 5 in 64-bit MS-VBA, and in RD-VBA, which has none to give; so is any other. |
| 6.1.2.5.1.5 | FileDateTime | When it was last modified, a directory's too. Error 53 for what does not exist, 52 for a pattern. |
| 6.1.2.5.1.6 | FileLen | The length on the file system, not what a channel has written yet: 0 for a file open for Output, the length it had for one open for Append, and what was written for one open Binary - which is not what the specification says ("the size of the file immediately before it was opened"), but what MS-VBA gives. A directory's is 0. Error 53, 52 as FileDateTime. |
| 6.1.2.5.1.7 | FreeFile | As MS-VBAL specifies. |
| 6.1.2.5.1.8 | Loc | Random, Binary: the last record or byte read or written, 0 before either. Sequential, as MS-VBA counts it: Input, the bytes read divided by 128, plus 1 - the first block is read when the file is opened; Output and Append, the bytes written divided by 128. |
| 6.1.2.5.1.9 | LOF | What has been written included. |
| 6.1.2.5.1.10 | Seek | For Append, counted from where the appending began, as MS-VBA counts it: 1 once the file is opened. |
6.1.2.5.2 Public Subroutines
Note
This section describes the implementation of MS-VBAL §6.1.2.5.2 Public Subroutines.
| § | Member | Notes |
|---|---|---|
| 6.1.2.5.2.1 | ChDir | Error 76 for a directory that does not exist, or a zero-length String. |
| 6.1.2.5.2.2 | ChDrive | Error 68 for a letter that is no drive. |
| 6.1.2.5.2.3 | FileCopy | Replaces the destination. A source open for Input is copied - the specification says "if the Source file is currently open, an error occurs", which MS-VBA raises (55) for any other mode only; so it does for an open destination. Error 53 for a source that does not exist, 52 for a pattern, 76 for a destination whose directory does not exist, 75 for one that is a directory. |
| 6.1.2.5.2.4 | Kill | Not a directory, nor a hidden or a system file: Kill "*" leaves them. Error 53 when nothing matches, 55 when a match is open, 75 when one is read-only. |
| 6.1.2.5.2.5 | MkDir | Error 75 when a directory or a file of the name exists, 76 when the directory it would be in does not. |
| 6.1.2.5.2.6 | RmDir | Error 75 for one that holds a file or a directory, 76 for one that does not exist - a file, a pattern. |
| 6.1.2.5.2.7 | SetAttr | Exactly the attributes given: vbReadOnly, vbHidden, vbSystem, vbArchive - any other is error 5. A file open for Input is given them - the specification says setting those of an open file is an error, which MS-VBA raises (55) for any other mode only. Error 53 for what does not exist, 52 for a pattern. |