# Folder class
{: .no_toc }

A folder inside the IDE's virtual file system. Extends [**FileSystemItem**](/tB/Packages/tbIDE/FileSystemItem.md) with child-enumeration capability --- [**Count**](#count), [**Item**](#item), and standard **For Each** iteration that yields each child as a [**FileSystemItem**](/tB/Packages/tbIDE/FileSystemItem.md) (use `TypeOf` to discriminate folders from files).

A **Folder** also inherits the universal [**FileSystemItem**](/tB/Packages/tbIDE/FileSystemItem.md) members --- [**Name**](/tB/Packages/tbIDE/FileSystemItem.md#name), [**Path**](/tB/Packages/tbIDE/FileSystemItem.md#path), [**Type**](/tB/Packages/tbIDE/FileSystemItem.md#type), [**Parent**](/tB/Packages/tbIDE/FileSystemItem.md#parent). The most common entry point is [**Host.CurrentProject.RootFolder**](/tB/Packages/tbIDE/Project.md#rootfolder), and the most common operation is a **For Each** recursive traversal.

```tb check_build
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
            ' …process the file
        End If
    Next
End Sub
```

> [!IMPORTANT]
> The twinBASIC IDE is multi-threaded. The same folder can change while an addin holds a reference to it --- files arrive, files disappear, indices renumber. The supported way to traverse a folder is **For Each**; index-based access through [**Count**](#count) / [**Item**](#item) races against the IDE's own threads and will sometimes miss or duplicate entries. Always prefer **For Each** for traversal.

* TOC
{:toc}

## Properties

### Count
{: .no_toc }

Number of items currently in the folder. **Long**, read-only.

> [!IMPORTANT]
> The value can change between two reads --- the IDE is multi-threaded. **Do not** use this as a `For i = 0 To Count - 1` loop bound; use **For Each** instead.

### IsPackagesFolder
{: .no_toc }

**True** if this folder is the project's special `Packages` folder (the one that contains every referenced package's source tree). **Boolean**, read-only.

Useful when traversing the project for source-search purposes --- an addin that searches user code will usually want to *skip* the package sources:

```tb check_build
Dim folder As tbIDE.Folder
Dim searchInsidePackages As Boolean
If folder.IsPackagesFolder And Not searchInsidePackages Then Exit Sub
```

### Item
{: .no_toc }

Indexed or named access to a child item. **DefaultMember** --- so `folder(0)` is equivalent to `folder.Item(0)`, and `folder("MainModule.twin")` is equivalent to `folder.Item("MainModule.twin")`.

Syntax: *folder*( *IndexOrName* ) **As** [**FileSystemItem**](/tB/Packages/tbIDE/FileSystemItem.md)

*IndexOrName*
: A **Variant** --- either a zero-based **Long** index or a **String** child name.

> [!IMPORTANT]
> Numeric indices race against the IDE's own threads --- the item at index `n` may have changed identity by the time the call returns. Named lookup is safer; **For Each** traversal is safer still.
