BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Path

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TIllegalArgumentException
    • TInvalidEnumException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
    • IIterable
    • IIterator
    • ICloseable

    Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts

    Color

    • Introduction
    • SColor8
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • FileSystem

    • Introduction
    • IFileWalker
    • SFileAttributes
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • Glob

    • Introduction
    • EGlobOptions
    • TGlobIter
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
  • BRL.Math
  • Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject

    MaxUnit

    • Introduction
    • TTest
    • TAssert
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • Path

    • Introduction
    • TPath
    • IPathWalker
    • SPathAttributes
    • TPathDirIterator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PolledInput
  • BRL.RamStream
  • Random

    • Introduction
    • TRandomDefault

    RectPacker

    • Introduction
    • EPackingMethod
    • SPackedRect
    • TPackedSheet
    • TRectPacker

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Time

    • Introduction
    • ETimeUnit
    • TTimeoutException

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Pub

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • StdC

    • Introduction
    • SDateTime
  • Pub.xmmintrin

Collections

    IntMap

    • Introduction
    • TIntMap

    ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    ObjectMap

    • Introduction
    • TObjectMap

    PtrMap

    • Introduction
    • TPtrMap

    StringMap

    • Introduction
    • TStringMap

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

Math

    Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI

    Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

Random

    Core

    • Introduction
    • TRandom
  • Random.PRVHASH
  • Random.Secure
  • SFMT

    • Introduction
    • TSFMTRandom
  • Random.Squares
  • Random.Xoshiro

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType

Text

    CP932Encoding

    • Text.CP932Encoding

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Encoding

    • Text.Encoding

    Format

    • Introduction
    • TFormatter

    Graphviz

    • Introduction
    • TGVGraphviz
    • TAGraph

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Markdown

    • Introduction
    • TMarkdown
    • IMDRenderer

    Pikchr

    • Introduction
    • EPikChrFlags

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute
Edit

BRL.Path

BRL.Path provides an object-oriented, cross-platform way to represent and work with file system paths.

At its core is the TPath type, which wraps a normalized path string and provides convenient operations for:

  • Joining and transforming paths (including the / operator).
  • Resolving and relativizing paths (#Resolve and Relativize).
  • Querying the filesystem (#Exists, IsFile, IsDir, Size, timestamps, etc).
  • Creating, deleting, renaming and copying files/directories.
  • Iterating directory contents (#IterDir / List).
  • Globbing and pattern matching (#Glob, GlobIter, MatchGlob).
  • Walking a directory tree (#Walk).

The module is designed to behave consistently whether using the native filesystem or the virtual filesystem when BRL.Io / MaxIO is enabled.

Quick start

SuperStrict

Framework brl.standardio
Import BRL.Path

Local p:TPath = New TPath("src") / "core" / "main.bmx"

Print p.ToString()   ' src/core/main.bmx
Print p.Name()       ' main.bmx
Print p.BaseName()   ' main
Print p.Extension()  ' bmx
Print p.Parent().ToString() ' src/core

Path normalization

When a TPath is created, the path is normalized:

  • Backslashes are converted to forward slashes (\ → /).
  • Trailing slashes are removed (except for a root path such as /).

This keeps equality comparisons stable and predictable.

Joining paths

Use Join, Child, or the / operator:

Local root:TPath = New TPath("/etc")
Local q:TPath = root / "init.d" / "reboot"

Print q.ToString() ' /etc/init.d/reboot

If the right-hand side is a rooted path, it replaces the left-hand side:

Local a:TPath = New TPath("a/b")
Local b:TPath = a / "/x/y"
Print b.ToString() ' /x/y

Resolve and Relativize

Resolve appends a relative path (or replaces the base if the argument is rooted):

Local base:TPath = New TPath("/a/b")
Local resolved:TPath = base.Resolve("c/d")
Print resolved.ToString() ' /a/b/c/d

Relativize constructs a relative path from one path to another:

Local p:TPath = New TPath("/a/b")
Local q:TPath = New TPath("/a/b/c/d")
Local r:TPath = p.Relativize(q)

Print r.ToString() ' c/d

Relativization is the inverse of resolution. For normalized paths p and relative q:

p.Relativize(p.Resolve(q)).Equals(q)

A relative path cannot be constructed if only one of the paths is rooted, or if rooted paths have different root components.

Querying the filesystem

TPath exposes filesystem queries through simple methods:

  • Exists
  • FileType, IsFile, IsDir
  • Size
  • ModifiedTime / ModifiedDateTime
  • CreatedTime / CreatedDateTime
Local p:TPath = New TPath("README.md")
If p.Exists() Then
    Print "Size: " + p.Size()
    Print "Modified: " + p.ModifiedDateTime().ToString()
End If

Creating, deleting, renaming and copying

Local dir:TPath = New TPath("build")
dir.CreateDir(True)

Local file:TPath = dir / "out.txt"
file.CreateFile()

file.CopyFileTo(dir / "out_copy.txt")

Local moved:TPath
If file.RenameTo(dir / "moved.txt", moved) Then
    Print "Moved to: " + moved.ToString()
End If

Directory listing

Use IterDir to iterate lazily, or List to build an array.

The iterator holds an open directory handle while iterating; if you exit early, close it (or use a Using block).

Using
    Local it:TPathDirIterator = New TPath("src").IterDir()
Do
    For Local p:TPath = EachIn it
        Print p.Name()
    Next
End Using

Globbing

Glob and GlobIter expand glob patterns to matching filesystem entries.

Supported pattern features include:

  • * matches zero or more characters within a segment.
  • ? matches a single character within a segment.
  • Character classes: [abc], [a-z], and negated [!abc] / [^abc].
  • Backslash escaping (unless EGlobOptions.NoEscape is set).
  • Brace expansion {a,b} (textual expansion before globbing).
  • ** globstar recursion when EGlobOptions.GlobStar is enabled.

By default, wildcard patterns do not match entries whose names begin with .. Enable EGlobOptions.Period to include dotfiles.

Iterating results (recommended)

Using
    Local it:TPathIterator = New TPath("src").GlobIter("**/*.bmx", EGlobOptions.GlobStar)
Do
    For Local p:TPath = EachIn it
        Print p.ToString()
    Next
End Using

Including files in the starting directory

A pattern of the form **/pattern matches only files below the starting directory (because the / is required).

To include files in the starting directory as well, combine patterns using brace expansion:

Local p:TPath = New TPath("examples")

Using
    Local it:TPathIterator = p.GlobIter("{*.bmx,**/*.bmx}", EGlobOptions.GlobStar)
Do
    For Local f:TPath = EachIn it
        Print f.Name()
    Next
End Using

Matching without filesystem access

MatchGlob matches a path against a pattern without touching the filesystem.

This is useful for filtering paths produced by other traversal methods:

Local p:TPath = New TPath("/path/to/sub/file.txt")
If p.MatchGlob("sub/*.txt") Then
    Print "Matched!"
End If

Walking a file tree

Walk traverses a directory tree and calls an IPathWalker for each entry.

Type TPrintWalker Implements IPathWalker
    Method WalkPath:EFileWalkResult(attributes:SPathAttributes Var)
        Print attributes.GetPath().ToString()
        Return EFileWalkResult.OK
    End Method
End Type

New TPath(".").Walk(New TPrintWalker)

Traversal can be configured using EFileWalkOption (for example, following symlinks) and the maxDepth parameter.

Resource management and Using

Iterators returned by IterDir and GlobIter may hold native resources (directory handles). If the iterator is not fully consumed, close it explicitly, or prefer a Using block:

Using
    Local it:TPathIterator = New TPath("src").GlobIter("**/*.bmx", EGlobOptions.GlobStar)
Do
    For Local p:TPath = EachIn it
        Print p.Name()
        Exit ' stop early, resources are still released at End Using
    Next
End Using

Provides the TPath class for representing and manipulating filesystem paths,

Types

TypeDescription
TPathClass representing and manipulating file system paths.
TPathDirIteratorIterator over the direct children of a directory TPath.

Interfaces

InterfaceDescription
IPathWalkerInterface for receiving callbacks during a file tree walk.

Structs

StructDescription
SPathAttributesStructure representing file or directory attributes.
← BRL.OpenALAudioTPath →
  • Quick start
  • Path normalization
  • Joining paths
  • Resolve and Relativize
  • Querying the filesystem
  • Creating, deleting, renaming and copying
  • Directory listing
  • Globbing
    • Iterating results (recommended)
    • Including files in the starting directory
  • Matching without filesystem access
  • Walking a file tree
  • Resource management and Using
  • Types
  • Interfaces
  • Structs
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
Resources
More
GitHubStarChat on Discord
Copyright © 2026 Bruce A Henderson