# tbFileSysTools Package
{: .no_toc }

**Author:** GCuser99. **Version:** 1.9.0.0. **On GitHub:** [GCuser99/tbFileSysTools](https://github.com/GCuser99/tbFileSysTools), in the folder *Package*.

The **tbFileSysTools** contributed package, listed on the Available Packages tab of Project Settings as *File System Tools - Modern Replacement for FSO*, reads and changes files, folders and drives, as the **FileSystemObject** of the Scripting Runtime does, and is written in twinBASIC. It reads and writes text files in any Windows code page, with detection of the encoding and handling of byte-order marks (BOMs), detects and converts line endings, streams files of any size, and works with paths longer than 260 characters.

It has two ways in. The [**FileSystemTools**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md) module holds the code, as procedures that a project calls by name, with no object to create. The [**FileSystemObject**](/tB/Packages/Contributed/tbFileSysTools/FileSystemObject.md) class has the same procedures as members of an object, for code written for the Scripting Runtime. The objects that both return, [**File**](/tB/Packages/Contributed/tbFileSysTools/File.md), [**Folder**](/tB/Packages/Contributed/tbFileSysTools/Folder.md), [**Drive**](/tB/Packages/Contributed/tbFileSysTools/Drive.md) and [**TextStream**](/tB/Packages/Contributed/tbFileSysTools/TextStream.md), and the collections [**Files**](/tB/Packages/Contributed/tbFileSysTools/Files.md), [**Folders**](/tB/Packages/Contributed/tbFileSysTools/Folders.md) and [**Drives**](/tB/Packages/Contributed/tbFileSysTools/Drives.md), have the members of the Scripting Runtime's objects of the same names, and some more.

```tb check_build check_run
Dim work As String, path As String
work = BuildPath(Environ$("TEMP"), GetTempName("fst", ""))
CreateFolder work
path = BuildPath(work, "notes.txt")

' Write a string as UTF-8 with a byte-order mark, then ask what the file holds.
StringToTextFile "caf" & ChrW$(233) & vbCrLf & "ok", path, encUtf8Bom
Debug.Print GetFileEncoding(path) = encUtf8Bom    ' True
Debug.Print GetFileLineEnding(path) = nlWindows   ' True
Debug.Print Len(TextFileToString(path))           ' 8

' Read it line by line; the encoding is found from the BOM.
Dim ts As TextStream
Set ts = OpenTextFile(path)
Do Until ts.AtEndOfStream
    Debug.Print Len(ts.ReadLine)
Loop
ts.Close
' Output:
' True
' True
' 8
' 4
' 2

DeleteFolder work
```

The package is published under the MIT licence.

The public types of the package are the module and the eight classes on these pages, and the enumerations that the module declares. Three private modules, **FSTShared** (shared file code and the error mapping), **TextCodec** (encoding, decoding and detection) and **WinAPI** (Windows declarations), are not part of the interface and are not described.

## Differences from the Scripting Runtime

A call that works with the Scripting Runtime's **FileSystemObject** keeps its name here. These are the differences.

**Added members.**

- Whole files: [**StringToTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#stringtotextfile), [**TextFileToString**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textfiletostring), [**ArrayToTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#arraytotextfile), [**TextFileToArray**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textfiletoarray), [**ReadStream**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#readstream), [**WriteStream**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#writestream), [**NormalizeTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#normalizetextfile) and [**MergeTextFiles**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#mergetextfiles).
- Detection: [**GetFileEncoding**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfileencoding) and [**GetFileLineEnding**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfilelineending).
- Searching and locks: [**FindInTextFiles**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#findintextfiles), [**FileContainsText**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#filecontainstext) and [**IsFileLocked**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#isfilelocked).
- Paths and directories: [**CleanFileName**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#cleanfilename), [**GetRelativePath**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getrelativepath), [**GetFilePaths**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfilepaths), [**GetFileType**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfiletype), [**GetSpecialFolderPath**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getspecialfolderpath), [**GetCurrentDir**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getcurrentdir), [**SetCurrentDir**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#setcurrentdir) and [**Rename**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#rename).
- On [**File**](/tB/Packages/Contributed/tbFileSysTools/File.md): **ContainsText**, **Encoding**, **ExtensionName**, **HasAttribute**, **IsLocked**, **LineEnding**, **Normalize**, **Refresh**, **Rename**, **SetAttribute**, **ToStream**, **ToString** and **Version**. On [**Folder**](/tB/Packages/Contributed/tbFileSysTools/Folder.md): **HasAttribute**, **Refresh**, **Rename** and **SetAttribute**. On [**Drive**](/tB/Packages/Contributed/tbFileSysTools/Drive.md): **SerialNumberHex** and **UnsignedSerialNumber**. On [**TextStream**](/tB/Packages/Contributed/tbFileSysTools/TextStream.md): **Encoding**, **Flush** and **IsStreaming**.
- [**Files**](/tB/Packages/Contributed/tbFileSysTools/Files.md), [**Folders**](/tB/Packages/Contributed/tbFileSysTools/Folders.md) and [**Drives**](/tB/Packages/Contributed/tbFileSysTools/Drives.md) return an item by position as well as by name.
- Enumerations for the encodings, line endings and 25 special folders.

**Members with more arguments.** [**CreateFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#createfolder) can create the folders above the new one. [**DeleteFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#deletefile) and [**DeleteFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#deletefolder) can ignore a missing target. [**GetAbsolutePathName**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getabsolutepathname) takes a base directory. [**GetTempName**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#gettempname) takes a prefix, an extension and a folder to check.

**Missing members.** None. Every member of the Scripting Runtime's **FileSystemObject**, **File**, **Folder**, **Drive** and **TextStream** is here, and so are **Count**, **Item** and the enumerator of the three collections, and the **Add** method of **Folders**. **Drives** of the class [**FileSystemObject**](/tB/Packages/Contributed/tbFileSysTools/FileSystemObject.md#drives) is a function, called with or without parentheses.

**Arguments that mean something else.** The Scripting Runtime selects the encoding of a text file with a **Boolean** (*Unicode*, in **CreateTextFile**) or a **Tristate** (*Format*, in **OpenTextFile** and **OpenAsTextStream**). Here the argument is a [**TextEncoding**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textencoding). Code that passes **True** or **TristateTrue**, which is -1, gets **encAutoDetect**, and for writing that is UTF-8, not UTF-16. The defaults also differ: a text file is written in UTF-8 without a BOM, where the Scripting Runtime writes ANSI, and a file opened for reading has its encoding detected, where the Scripting Runtime reads ANSI.

**Results that differ.**

- [**GetSpecialFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getspecialfolder) accepts 25 folders, and not only the Windows, System and Temporary folders. Like the Scripting Runtime's it returns a **Folder**; [**GetSpecialFolderPath**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getspecialfolderpath) returns the path as a **String**, for a folder that may not exist.
- [**FileAttribute**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#fileattribute) has no *Volume* (8) and no *Alias* (1024). The label of a volume is [**Drive.VolumeName**](/tB/Packages/Contributed/tbFileSysTools/Drive.md#volumename), and an alias is **faReparsePoint**. [**File**](/tB/Packages/Contributed/tbFileSysTools/File.md#setattribute) and [**Folder**](/tB/Packages/Contributed/tbFileSysTools/Folder.md#setattribute) add **SetAttribute** and **HasAttribute**, which change and test one attribute.
- [**Folder.Size**](/tB/Packages/Contributed/tbFileSysTools/Folder.md#size), [**CopyFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#copyfolder), [**DeleteFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#deletefolder) and [**GetFilePaths**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfilepaths) with *recursive* do not enter directory junctions and symbolic links. The Scripting Runtime does, and counts the target of a link twice when it is in the same tree: 2,500 bytes there for a folder that holds 1,500. Its **CopyFolder** copies the files of the target into the copy, and its **DeleteFolder** deletes them.
- [**BuildPath**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#buildpath) and [**GetParentFolderName**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getparentfoldername) turn `/` into `\`. `BuildPath("C:\a", "b/c")` returns `C:\a\b\c` and the Scripting Runtime `C:\a\b/c`; `GetParentFolderName("C:/a/b.txt")` returns `C:\a` and the Scripting Runtime `C:/a`.
- [**GetAbsolutePathName**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getabsolutepathname) raises error 52 for an empty string, where the Scripting Runtime returns the current directory.
- [**CopyFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#copyfile), [**CopyFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#copyfolder), [**MoveFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefile) and [**MoveFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefolder) put the source inside an existing destination folder, whether or not the destination ends in a backslash. The Scripting Runtime does so only with a backslash. Without one it raises error 70 for **CopyFile**, 58 for **MoveFile** and **MoveFolder**, and **CopyFolder** copies the contents of the source straight into the folder.
- [**MoveFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefile) moves a folder when *source* names one. The Scripting Runtime raises error 53.
- [**GetFileVersion**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfileversion) raises error 53 for a file that does not exist. The Scripting Runtime raises the Windows code `0x80070002` as the error number.
- At the end of a stream, [**ReadAll**](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#readall) returns an empty string and [**Skip**](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#skip) does nothing, where the Scripting Runtime raises error 62. A closed stream raises 52 here and 91 there.
- [**Files.Item**](/tB/Packages/Contributed/tbFileSysTools/Files.md#item), [**Folders.Item**](/tB/Packages/Contributed/tbFileSysTools/Folders.md#item) and [**Drives.Item**](/tB/Packages/Contributed/tbFileSysTools/Drives.md#item) take a position as well as a name. A name or a position that is not in the collection raises 53, 76 and 68, the numbers that the Scripting Runtime raises for a name that is not in the three; for a position it raises error 5.
- [**GetTempName**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#gettempname) returns eight random letters and digits and `.tmp`. The Scripting Runtime returns `rad` and five hexadecimal digits.
- A path longer than 260 characters works in most procedures. The Scripting Runtime does not accept it: **FileExists** and **FolderExists** return **False** for it, **GetFile** raises error 53 and **OpenTextFile** raises 76.

**The same.** For these failures the two raise the same error numbers: a missing file (53) or folder (76) from **GetFile**, **GetFolder**, **CopyFile**, **DeleteFile**, **DeleteFolder** and **OpenTextFile**; an existing folder or destination (58) from **CreateFolder**, **CopyFile**, **MoveFile** and **CreateTextFile**; a missing parent folder (76) from **CreateFolder**; a drive that does not exist (68) and a path that is longer than a drive (5) from **GetDrive**; a read-only destination or file (70) from **CopyFile**, **DeleteFile** and **CreateTextFile**, and a folder with a read-only file in it (70) from **DeleteFolder**; an unreadable folder (70) from **Files**, **SubFolders** and **Size**; the wrong direction of a stream (54) and a read at the end (62) from **TextStream**. Both match a pattern against the 8.3 name of a file in **CopyFile**, **DeleteFile** and **MoveFile**, and both accept `C:` as the item of **Drives**.

## Using the package with the Scripting Runtime

The package declares types that have the same names as those of the Scripting Runtime library: **FileSystemObject**, **File**, **Folder**, **Drive**, **Files**, **Folders**, **Drives**, **TextStream**, and the enumerations **FileAttribute**, **IOMode**, **SpecialFolderConst**, **StandardStreamTypes** and **DriveTypeConst** with their members, such as **ForReading**, **Normal** and **Fixed**. In a project that references both libraries, a bare name is found in the library that is listed first among the references, and no error is reported for the other. With the package first, `Dim fso As New FileSystemObject` creates the package's class, and `Dim f As File` is the package's type. With the Scripting Runtime first, they are the Scripting Runtime's: `f.Encoding` then fails to compile (TB5027, *Unrecognized member 'Encoding' on type 'IFile'*), and `fso.BuildPath("C:\a", "b/c")` returns `C:\a\b/c`. The enumeration members (**ForReading**, **Normal**, **Fixed**) compile in either order, and their values are the same in both libraries.

Write the name of the library before the type to be sure which one is meant. Both forms compile in either order:

```tb check_build
Dim fso As New tbFileSysTools.FileSystemObject
Dim f As tbFileSysTools.File
Set f = fso.GetFile(fso.BuildPath(fso.GetSpecialFolderPath(sfSystemFolder), "kernel32.dll"))
Debug.Print f.Size
```

The other ways out are to remove the reference to the Scripting Runtime, or to list **tbFileSysTools** above it in the Enabled Libraries list of Project Settings, which is in order of priority. The procedures of the module (**FileExists**, **GetFile**, **CopyFile** and the rest) do not collide with anything in the Scripting Runtime, which has no module-level procedures.

## Errors

The procedures raise the error numbers that VB6 uses for the same failures. **Err.Source** names the operation, such as `CopyFile`, and **Err.Description** names the path. The errors of [**OpenTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#opentextfile), [**CreateTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#createtextfile) and the other procedures that open a stream have an empty **Err.Source** and only the standard text of their number, without the path. Each entry says which numbers it raises.

- 5 -- *Invalid procedure call or argument*: a wildcard in a destination, a folder copied into itself, a text procedure given a binary file, a value that is not a member of an enumeration, a path given to [**Folders.Add**](/tB/Packages/Contributed/tbFileSysTools/Folders.md#add) as a name, a string that is not a drive, and an empty search text.
- 7 -- *Out of memory*: a whole file that is too large for one array or **String** (more than 2 GB).
- 52 -- *Bad file name or number*: a name with a character that Windows does not allow, or a reserved device name such as `con`, and a closed [**TextStream**](/tB/Packages/Contributed/tbFileSysTools/TextStream.md).
- 53 -- *File not found*, and a name or a position that is not in a [**Files**](/tB/Packages/Contributed/tbFileSysTools/Files.md).
- 54 -- *Bad file mode*: a read on a stream open for writing, or the reverse.
- 58 -- *File already exists*. The text says *File* also when a folder is in the way.
- 62 -- *Input past end of file*.
- 68 -- *Device unavailable*: a drive letter that is not in use, and a name or a position that is not in a [**Drives**](/tB/Packages/Contributed/tbFileSysTools/Drives.md).
- 70 -- *Permission denied*: access is refused, or the file is in use, or a read-only file is to be replaced or a folder holds one that stops it from being deleted.
- 71 -- *Disk not ready*: a drive with no media.
- 75 -- *Path/File access error*: any other Windows failure. The text ends with the Windows code, such as 206 for a path that is too long.
- 76 -- *Path not found*, and a name or a position that is not in a [**Folders**](/tB/Packages/Contributed/tbFileSysTools/Folders.md).

Windows reports a failure with its own code, and the package maps it to one of those numbers: *file not found* (2) to 53, *path not found* (3) and *bad directory name* (267) to 76, *file exists* (80 and 183) to 58, *access denied* and the sharing violations (5, 32 and 33) to 70, and *invalid name* (123) to 52.

> [!NOTE] 1.9.0.0
> A few failures raise a number that is not the one the same failure raises elsewhere in the package. The sample shows the first two.
>
> - A file that is held open with exclusive access raises the unspecified error -2147467259 when it is read, by [**TextFileToString**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textfiletostring), [**GetFileEncoding**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfileencoding), [**ReadStream**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#readstream) and the other procedures that read a whole file. Writing to it raises 70.
> - A reserved device name, such as `con` or `nul`, raises 52 in the procedures that write a file ([**StringToTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#stringtotextfile), [**ArrayToTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#arraytotextfile), [**CreateTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#createtextfile), [**OpenTextFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#opentextfile) with *create* **True**, [**Folder.CreateTextFile**](/tB/Packages/Contributed/tbFileSysTools/Folder.md#createtextfile)) and in [**CopyFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#copyfile). It raises other numbers elsewhere. [**CreateFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#createfolder) raises 75 for `con` and 76 for `nul`; [**MoveFile**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefile) raises 75 for `con`, and for `nul` it raises nothing, which has a warning of its own; [**MoveFolder**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefolder) raises 75 for `con` and 70 for `nul`; [**Rename**](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#rename) raises 5.
> - [**Folder.Files**](/tB/Packages/Contributed/tbFileSysTools/Folder.md#files), [**SubFolders**](/tB/Packages/Contributed/tbFileSysTools/Folder.md#subfolders) and [**Size**](/tB/Packages/Contributed/tbFileSysTools/Folder.md#size) raise error 76 for a folder whose path has 258 characters or more.

```tb check_build check_run
Dim work As String, p As String, s As String, fn As Long
work = BuildPath(Environ$("TEMP"), GetTempName("fst", ""))
CreateFolder work
p = BuildPath(work, "a.txt")
StringToTextFile "x", p

On Error Resume Next
fn = FreeFile()
Open p For Binary Access Read Write Lock Read Write As #fn
s = TextFileToString(p)
Debug.Print Err.Number                              ' -2147467259
Err.Clear
StringToTextFile "y", p
Debug.Print Err.Number                              ' 70
Err.Clear
Close #fn

StringToTextFile "x", BuildPath(work, "con")
Debug.Print Err.Number                              ' 52
Err.Clear
CreateFolder BuildPath(work, "con")
Debug.Print Err.Number                              ' 75
Err.Clear
Rename p, "con"
Debug.Print Err.Number                              ' 5
Err.Clear
On Error GoTo 0

DeleteFolder work
```

In the procedures that read or write the text or the bytes of a file, a file that does not exist raises error 53, and a folder that does not exist raises 76.

## Classes and modules

- [FileSystemTools](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md) -- the module that holds the procedures, and the enumerations
  - [ArrayToTextFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#arraytotextfile) -- writes the elements of a String array to a text file, one per line
  - [BuildPath](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#buildpath) -- joins a folder path and a name
  - [CleanFileName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#cleanfilename) -- removes from a file name the characters that Windows does not allow
  - [CopyFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#copyfile) -- copies one or more files
  - [CopyFolder](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#copyfolder) -- copies a folder and everything in it
  - [CreateFolder](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#createfolder) -- creates a folder
  - [CreateTextFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#createtextfile) -- creates a text file and returns a TextStream open for writing
  - [DeleteFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#deletefile) -- deletes one or more files
  - [DeleteFolder](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#deletefolder) -- deletes a folder and everything in it
  - [DriveExists](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#driveexists) -- returns whether a drive exists
  - [FileContainsText](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#filecontainstext) -- returns whether a text file contains a piece of text
  - [FileExists](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#fileexists) -- returns whether a file exists
  - [FindInTextFiles](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#findintextfiles) -- returns the paths of the text files in a folder that contain a piece of text
  - [FolderExists](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#folderexists) -- returns whether a folder exists
  - [GetAbsolutePathName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getabsolutepathname) -- returns the full path for a path specification
  - [GetBaseName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getbasename) -- returns the last component of a path without its extension
  - [GetCurrentDir](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getcurrentdir) -- returns the current directory
  - [GetDrive](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getdrive) -- returns a Drive object
  - [GetDriveName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getdrivename) -- returns the drive part of a path
  - [GetDrives](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getdrives) -- returns a Drives collection of every drive
  - [GetExtensionName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getextensionname) -- returns the extension of the last component of a path
  - [GetFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfile) -- returns a File object
  - [GetFileEncoding](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfileencoding) -- returns the text encoding of a file
  - [GetFileLineEnding](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfilelineending) -- returns the line-ending style of a text file
  - [GetFileName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfilename) -- returns the last component of a path
  - [GetFilePaths](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfilepaths) -- returns the paths of the files in a folder
  - [GetFileType](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfiletype) -- returns the type description of a file or folder
  - [GetFileVersion](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfileversion) -- returns the version of an executable file
  - [GetFolder](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getfolder) -- returns a Folder object
  - [GetParentFolderName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getparentfoldername) -- returns the path of the folder that holds the last component of a path
  - [GetRelativePath](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getrelativepath) -- returns the path that leads from one path to another
  - [GetSpecialFolder](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getspecialfolder) -- returns a Folder object for a well-known Windows folder
  - [GetSpecialFolderPath](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getspecialfolderpath) -- returns the path of a well-known Windows folder
  - [GetStandardStream](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#getstandardstream) -- returns a TextStream for standard input, output or error
  - [GetTempName](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#gettempname) -- returns a random name for a temporary file or folder
  - [IsFileLocked](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#isfilelocked) -- returns whether a file is in use
  - [MergeTextFiles](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#mergetextfiles) -- joins two text files into one
  - [MoveFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefile) -- moves one or more files
  - [MoveFolder](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#movefolder) -- moves one or more folders
  - [NormalizeTextFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#normalizetextfile) -- rewrites a text file with a chosen encoding and line ending
  - [OpenTextFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#opentextfile) -- opens a text file and returns a TextStream
  - [ReadStream](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#readstream) -- reads a file into a byte array
  - [Rename](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#rename) -- renames a file or folder in place
  - [SetCurrentDir](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#setcurrentdir) -- sets the current directory
  - [StringToTextFile](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#stringtotextfile) -- writes a string to a text file
  - [TextFileToArray](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textfiletoarray) -- reads a text file into an array of lines
  - [TextFileToString](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textfiletostring) -- reads a text file into a string
  - [WriteStream](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#writestream) -- writes a byte array to a file
  - [TextEncoding](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#textencoding), [NewlineType](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#newlinetype), [IOMode](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#iomode), [SpecialFolderConst](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#specialfolderconst), [FileAttribute](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#fileattribute), [FileVersionSource](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#fileversionsource) and [StandardStreamTypes](/tB/Packages/Contributed/tbFileSysTools/FileSystemTools.md#standardstreamtypes) -- the enumerations
- [FileSystemObject](/tB/Packages/Contributed/tbFileSysTools/FileSystemObject.md) -- a class with the procedures of the module as members, for code written for the Scripting Runtime
- [Drive](/tB/Packages/Contributed/tbFileSysTools/Drive.md) -- a disk drive or a network share
  - [AvailableSpace](/tB/Packages/Contributed/tbFileSysTools/Drive.md#availablespace) -- returns the free bytes that the current user can use
  - [DriveLetter](/tB/Packages/Contributed/tbFileSysTools/Drive.md#driveletter) -- returns the letter of the drive
  - [DriveType](/tB/Packages/Contributed/tbFileSysTools/Drive.md#drivetype) -- returns the type of the drive
  - [FileSystem](/tB/Packages/Contributed/tbFileSysTools/Drive.md#filesystem) -- returns the name of the file system
  - [FreeSpace](/tB/Packages/Contributed/tbFileSysTools/Drive.md#freespace) -- returns the free bytes on the volume
  - [IsReady](/tB/Packages/Contributed/tbFileSysTools/Drive.md#isready) -- returns whether the drive can be queried
  - [Path](/tB/Packages/Contributed/tbFileSysTools/Drive.md#path) -- returns the path of the drive (default member)
  - [RootFolder](/tB/Packages/Contributed/tbFileSysTools/Drive.md#rootfolder) -- returns the root folder of the drive
  - [SerialNumber](/tB/Packages/Contributed/tbFileSysTools/Drive.md#serialnumber) -- returns the serial number as a signed Long
  - [SerialNumberHex](/tB/Packages/Contributed/tbFileSysTools/Drive.md#serialnumberhex) -- returns the serial number in the form that Explorer shows
  - [ShareName](/tB/Packages/Contributed/tbFileSysTools/Drive.md#sharename) -- returns the network path of the drive
  - [TotalSize](/tB/Packages/Contributed/tbFileSysTools/Drive.md#totalsize) -- returns the size of the volume
  - [UnsignedSerialNumber](/tB/Packages/Contributed/tbFileSysTools/Drive.md#unsignedserialnumber) -- returns the serial number as an unsigned number
  - [VolumeName](/tB/Packages/Contributed/tbFileSysTools/Drive.md#volumename) -- returns or sets the label of the volume
- [Drives](/tB/Packages/Contributed/tbFileSysTools/Drives.md) -- the collection of the drives
- [File](/tB/Packages/Contributed/tbFileSysTools/File.md) -- a file
  - [Attributes](/tB/Packages/Contributed/tbFileSysTools/File.md#attributes), [DateCreated](/tB/Packages/Contributed/tbFileSysTools/File.md#datecreated), [DateLastAccessed](/tB/Packages/Contributed/tbFileSysTools/File.md#datelastaccessed), [DateLastModified](/tB/Packages/Contributed/tbFileSysTools/File.md#datelastmodified), [Drive](/tB/Packages/Contributed/tbFileSysTools/File.md#drive), [Encoding](/tB/Packages/Contributed/tbFileSysTools/File.md#encoding), [ExtensionName](/tB/Packages/Contributed/tbFileSysTools/File.md#extensionname), [HasAttribute](/tB/Packages/Contributed/tbFileSysTools/File.md#hasattribute), [LineEnding](/tB/Packages/Contributed/tbFileSysTools/File.md#lineending), [Name](/tB/Packages/Contributed/tbFileSysTools/File.md#name), [ParentFolder](/tB/Packages/Contributed/tbFileSysTools/File.md#parentfolder), [Path](/tB/Packages/Contributed/tbFileSysTools/File.md#path), [ShortName](/tB/Packages/Contributed/tbFileSysTools/File.md#shortname), [ShortPath](/tB/Packages/Contributed/tbFileSysTools/File.md#shortpath), [Size](/tB/Packages/Contributed/tbFileSysTools/File.md#size), [Type](/tB/Packages/Contributed/tbFileSysTools/File.md#type), [Version](/tB/Packages/Contributed/tbFileSysTools/File.md#version) -- the properties
  - [ContainsText](/tB/Packages/Contributed/tbFileSysTools/File.md#containstext), [Copy](/tB/Packages/Contributed/tbFileSysTools/File.md#copy), [Delete](/tB/Packages/Contributed/tbFileSysTools/File.md#delete), [IsLocked](/tB/Packages/Contributed/tbFileSysTools/File.md#islocked), [Move](/tB/Packages/Contributed/tbFileSysTools/File.md#move), [Normalize](/tB/Packages/Contributed/tbFileSysTools/File.md#normalize), [OpenAsTextStream](/tB/Packages/Contributed/tbFileSysTools/File.md#openastextstream), [Refresh](/tB/Packages/Contributed/tbFileSysTools/File.md#refresh), [Rename](/tB/Packages/Contributed/tbFileSysTools/File.md#rename), [SetAttribute](/tB/Packages/Contributed/tbFileSysTools/File.md#setattribute), [ToStream](/tB/Packages/Contributed/tbFileSysTools/File.md#tostream), [ToString](/tB/Packages/Contributed/tbFileSysTools/File.md#tostring) -- the methods
- [Files](/tB/Packages/Contributed/tbFileSysTools/Files.md) -- the collection of the files of a folder
- [Folder](/tB/Packages/Contributed/tbFileSysTools/Folder.md) -- a folder
  - [Attributes](/tB/Packages/Contributed/tbFileSysTools/Folder.md#attributes), [DateCreated](/tB/Packages/Contributed/tbFileSysTools/Folder.md#datecreated), [DateLastAccessed](/tB/Packages/Contributed/tbFileSysTools/Folder.md#datelastaccessed), [DateLastModified](/tB/Packages/Contributed/tbFileSysTools/Folder.md#datelastmodified), [Drive](/tB/Packages/Contributed/tbFileSysTools/Folder.md#drive), [Files](/tB/Packages/Contributed/tbFileSysTools/Folder.md#files), [HasAttribute](/tB/Packages/Contributed/tbFileSysTools/Folder.md#hasattribute), [IsRootFolder](/tB/Packages/Contributed/tbFileSysTools/Folder.md#isrootfolder), [Name](/tB/Packages/Contributed/tbFileSysTools/Folder.md#name), [ParentFolder](/tB/Packages/Contributed/tbFileSysTools/Folder.md#parentfolder), [Path](/tB/Packages/Contributed/tbFileSysTools/Folder.md#path), [ShortName](/tB/Packages/Contributed/tbFileSysTools/Folder.md#shortname), [ShortPath](/tB/Packages/Contributed/tbFileSysTools/Folder.md#shortpath), [Size](/tB/Packages/Contributed/tbFileSysTools/Folder.md#size), [SubFolders](/tB/Packages/Contributed/tbFileSysTools/Folder.md#subfolders), [Type](/tB/Packages/Contributed/tbFileSysTools/Folder.md#type) -- the properties
  - [Copy](/tB/Packages/Contributed/tbFileSysTools/Folder.md#copy), [CreateTextFile](/tB/Packages/Contributed/tbFileSysTools/Folder.md#createtextfile), [Delete](/tB/Packages/Contributed/tbFileSysTools/Folder.md#delete), [Move](/tB/Packages/Contributed/tbFileSysTools/Folder.md#move), [Refresh](/tB/Packages/Contributed/tbFileSysTools/Folder.md#refresh), [Rename](/tB/Packages/Contributed/tbFileSysTools/Folder.md#rename), [SetAttribute](/tB/Packages/Contributed/tbFileSysTools/Folder.md#setattribute) -- the methods
- [Folders](/tB/Packages/Contributed/tbFileSysTools/Folders.md) -- the collection of the folders of a folder
  - [Add](/tB/Packages/Contributed/tbFileSysTools/Folders.md#add) -- creates a subfolder and adds it to the collection
- [TextStream](/tB/Packages/Contributed/tbFileSysTools/TextStream.md) -- reads or writes a text file a piece at a time
  - [AtEndOfLine](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#atendofline), [AtEndOfStream](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#atendofstream), [Column](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#column), [Encoding](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#encoding), [IsStreaming](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#isstreaming), [Line](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#line) -- the properties
  - [Close](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#close), [Flush](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#flush), [Read](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#read), [ReadAll](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#readall), [ReadLine](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#readline), [Skip](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#skip), [SkipLine](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#skipline), [Write](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#write), [WriteBlankLines](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#writeblanklines), [WriteLine](/tB/Packages/Contributed/tbFileSysTools/TextStream.md#writeline) -- the methods

## See Also

- [Open](/tB/Core/Open.md) statement -- the VBA statement that opens a file for input and output
- [FileSystem](/tB/Modules/FileSystem/index.md) module -- the VBA functions and statements for files and folders: **FileCopy**, **Kill**, **MkDir**, **Dir** and the rest
- [FileProps](/tB/Packages/Contributed/FileProps/index.md) package -- the Windows shell properties of a file
- [TBMANLIB_Dialog](/tB/Packages/Contributed/TBMANLIB_Dialog/index.md) package -- the Open, Save and folder dialogs, with path helpers
- [tbRegExp](/tB/Packages/Contributed/tbRegExp/index.md) package -- regular expressions, by the same author

## Test cases

The notes and warnings of this section are checked by the test cases in [tbFileSysTools-tests.twinproj](tbFileSysTools-tests.twinproj), a twinBASIC project. It uses tbFileSysTools as a [linked package](/Features/Packages/Linked.md#manual-management): put the package's `.twinpack` in `%APPDATA%\twinBASIC\packages`, then run the project, and each case prints whether it passes.
