BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›BRL

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
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

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

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    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
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

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

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

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

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    CSV

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

    Format

    • Introduction
    • TFormatter

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

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

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

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

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

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

PUB

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

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    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

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • 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
Edit

BRL.FileSystem

The BlitzMax filesystem module contains commands to perform operations on the computer's files and directories.

OpenFile, ReadFile and WriteFile return a stream object for reading and or writing data to files.

Directories can be examined file by file using a combination of the ReadDir, NextFile and CloseDir commands, or LoadDir can be used to read the file names of a directory into a string array.

File properties can be examined with the FileType, FileTime, FileSize and FileMode commands.

Files and directories (folders) can be created and deleted with the CreateFile, CreateDir DeleteFile and DeleteDir commands.

Finally, the FileSystem module contains various utility functions for handling file paths in a system independent manner. These commands include RealPath, StripDir, StripExt, StripAll, ExtractDir and ExtractExt.

Functions

Function StripDir$( path$ )

Strip directory from a file path

Example

' stripdir.bmx

SuperStrict

Print StripDir("mypath/myfile.bmx") ' prints myfile.bmx


Function StripExt$( path$ )

Strip extension from a file path

Example

' stripext.bmx

SuperStrict

Print StripExt("mypath/myfile.bmx") ' prints mypath/myfile


Function StripAll$( path$ )

Strip directory and extension from a file path

Example

' stripall.bmx

SuperStrict

Print StripAll("mypath/myfile.bmx") ' prints myfile


Function StripSlash$( path$ )

Strip trailing slash from a file path

StripSlash will not remove the trailing slash from a 'root' path. For example, "/" or (on Win32 only) "C:/".

Example

' stripslash.bmx
SuperStrict

Print StripSlash("mypath/") ' prints mypath


Function ExtractDir$( path$ )

Extract directory from a file path

Example

' extractdir.bmx

SuperStrict

Print ExtractDir("mypath/myfile.bmx")   ' prints mypath


Function ExtractExt$( path$ )

Extract extension from a file path

Example

' extractext.bmx

SuperStrict

Print ExtractExt("mypath/myfile.bmx")   ' prints bmx


Function CurrentDir$()

Get Current Directory

Returns

The current directory

Example

' currentdir.bmx
SuperStrict

Local cd:String = CurrentDir()
Print "CurrentDir()="+cd


Function RealPath$( path$ )

Get real, absolute path of a file path

Example

' realpath.bmx

SuperStrict

Print RealPath("realpath.bmx")  'prints full path of this source

Print RealPath("..") 'prints full path of parent directory


Function FileType:Int( path$ )

Get file type

Returns

0 if file at path doesn't exist, FILETYPE_FILE (1) if the file is a plain file or FILETYPE_DIR (2) if the file is a directory

Example

' filetype.bmx

SuperStrict

Print FileType(".")     ' prints 2 for directory type
Print FileType("filetype.bmx")  ' prints 1 for file type
Print FileType("notfound.file") ' prints 0 for doesn't exist


Function FileTime:Long( path$, timetype:Int=FILETIME_MODIFIED )

Get file time

Returns

The time the file at path was last modified

Example

' filetime.bmx

SuperStrict

Print FileTime("filetime.bmx")


Function FileSize:Long( path$ )

Get file size

Returns

Size, in bytes, of the file at path, or -1 if the file does not exist

Example

' filesize.bmx

SuperStrict

' the following prints the size of this source file in bytes

Print FileSize("filesize.bmx")


Function FileMode:Int( path$ )

Get file mode

Returns

file mode flags

Example

' filemode.bmx
SuperStrict

' the following function converts the file mode to 
' the standard unix permission bits string

Function Permissions:String(mode:Int)
    Local testbit:Int, pos:Int
    Local p:String = "rwxrwxrwx"
    testbit = %100000000
    pos = 1
    Local res:String
    While (testbit)
        If mode & testbit 
            res :+ Mid(p, pos, 1)
        Else 
            res :+ "-"
        EndIf
        testbit = testbit Shr 1
        pos :+ 1
    Wend
    Return res
End Function

Print Permissions(FileMode("filemode.bmx"))


Function SetFileMode( path$,Mode:Int )

Set file mode

Example

' setfilemode.bmx
SuperStrict

' the following makes this source file readonly
Local writebits:Int = %010010010

' read the file mode
Local mode:Int = FileMode("setfilemode.bmx")

'mask out the write bits to make readonly
mode = mode & ~writebits

'set the new file mode
SetFileMode("setfilemode.bmx",mode)


Function CreateFile:Int( path$ )

Create a file

Returns

True if successful

Example

' createfile.bmx
SuperStrict

Local success:Int = CreateFile("myfile")
If Not success Then
    RuntimeError "error creating file"
End If


Function CreateDir:Int( path$,recurse:Int=False )

Create a directory

If recurse is true, any required subdirectories are also created.

Returns

True if successful

Example

' createdir.bmx
SuperStrict

Local success:Int = CreateDir("myfolder")
If Not success Then
    RuntimeError "error creating directory"
End If


Function DeleteFile:Int( path$ )

Delete a file

Returns

True if successful

Example

' deletefile.bmx
SuperStrict

Local success:Int = DeleteFile("myfile")
If Not success RuntimeError "error deleting file"


Function RenameFile:Int( oldpath$,newpath$ )

Renames a file

Returns

True if successful

Example

SuperStrict

Local result:Int = CopyFile(BlitzMaxPath() + "\versions.txt", BlitzMaxPath() + "\versions2.txt")

If result = 0 Then
    RuntimeError "CopyFile not successful..."
End If

result = RenameFile(BlitzMaxPath() + "\versions.txt", BlitzMaxPath() + "\versions2.txt")

If result = 0 Then
    RuntimeError "Rename not successful..." ' as file already exist
End If


Function CopyFile:Int( src$,dst$ )

Copy a file

Returns

True if successful

Example

SuperStrict

Local result:Int = CopyFile(BlitzMaxPath() + "\versions.txt",  BlitzMaxPath() + "\versions2.txt")

If result = 0 Then  
    RuntimeError "CopyFile not successful..."
End If

result = RenameFile(BlitzMaxPath() + "\versions.txt", BlitzMaxPath() + "\versions2.txt")

If result = 0 Then
    RuntimeError "Rename not successful..." ' as file already exists
End If


Function CopyDir:Int( src$,dst$ )

Copy a directory

Returns

True if successful


Function DeleteDir:Int( path$,recurse:Int=False )

Delete a directory

Set recurse to true to delete all subdirectories and files recursively - but be careful!

Returns

True if successful

Example

' deletedir.bmx
SuperStrict

Local success:Int = DeleteDir("myfolder")
If Not success Then
    RuntimeError "error deleting directory"
End If


Function ChangeDir:Int( path$ )

Change current directory

Returns

True if successful

Example

' changedir.bmx

SuperStrict

Print "CurrentDir()="+CurrentDir()

' change current folder to the parent folder

ChangeDir ".."

' print new CurrentDir()

Print "CurrentDir()="+CurrentDir()


Function ReadDir:Byte Ptr( path$ )

Open a directory

Returns

A directory handle, or Null if the directory does not exist

Example

' readdir.bmx
SuperStrict

Local dir:Byte Ptr = ReadDir(CurrentDir())

If Not dir RuntimeError "failed to read current directory"

Repeat
    Local t:String = NextFile( dir )
    If t="" Exit
    If t="." Or t=".." Continue
    Print t 
Forever

CloseDir dir


Function NextFile$( dir:Byte Ptr )

Return next file in a directory

Returns

File name of next file in directory opened using ReadDir, or an empty string if there are no more files to read.

Example

'File System Example

SuperStrict

Local dir:Byte Ptr = ReadDir(BlitzMaxPath() )

If Not dir Then
    RuntimeError "Cannot open folder"
End If

Local file:String
Repeat
    
    file = NextFile(Dir) ' Get the filenames in folder
    Print file
    
Until file = ""

CloseDir(dir)


Function CloseDir( dir:Byte Ptr )

Close a directory

Example

'File System Example

SuperStrict

Local dir:Byte Ptr = ReadDir(BlitzMaxPath())

If Not dir Then
    RuntimeError "Cannot open folder"
End If

Local file:String
Repeat
    
    file = NextFile(dir) ' Get the filenames in folder
    Print file
    
Until Not file

CloseDir(dir)


Function LoadDir$[]( dir$,skip_dots:Int=True )

Load a directory

The skip_dots parameter, if true, removes the '.' (current) and '..' (parent) directories from the returned array.

Returns

A string array containing contents of dir

Example

' loaddir.bmx
SuperStrict

' declare a string array
Local files:String[] 
files = LoadDir(CurrentDir())

For Local t:String = EachIn files
    Print t 
Next


Function OpenFile:TStream( url:Object,readable:Int=True,writeable:Int=True )

Open a file for input and/or output.

This command is similar to the OpenStream command but will attempt to cache the contents of the file to ensure serial streams such as http: based url's are seekable. Use the CloseStream command when finished reading and or writing to a Stream returned by OpenFile.

Example

' openfile.bmx
SuperStrict

' the following prints the contents of this source file 

Local file:TStream = OpenFile("openfile.bmx")

If Not file RuntimeError "could not open file openfile.bmx"

While Not Eof(file)
    Print ReadLine(file)
Wend
CloseStream file


Function ReadFile:TStream( url:Object )

Open a file For Input.

This command is similar to the ReadStream command but will attempt to cache the contents of the file to ensure serial streams such as http: based url's are seekable. Use the CloseStream command when finished reading and or writing to a Stream returned by OpenFile.

Example

' readfile.bmx
' the following prints the contents of this source file 

SuperStrict

Local file:TStream = ReadFile("readfile.bmx")

If Not file RuntimeError "could not open file openfile.bmx"

While Not Eof(file)
    Print ReadLine(file)
Wend

CloseStream file


Function WriteFile:TStream( url:Object )

Open a file for output.

This command is identical to the WriteStream command.

Example

' writefile.bmx
SuperStrict

Local file:TStream = WriteFile("test.txt")

If Not file Then RuntimeError "failed to open test.txt file" 

WriteLine file,"hello world"

CloseStream file


Function CloseFile( stream:TStream )

Closes a file stream.

After performing file operations on an open file make sure to close the file stream with either CloseFile or the identical CloseStream command.

Example

SuperStrict

Local in:TStream = OpenFile(BlitzMaxPath() + "\versions.txt")
Local line:String

While Not Eof(in)
    line = ReadLine(in)
    Print line
Wend

CloseFile(in) ' can also use CloseStream(in)


← BRL.EventQueueBRL.FreeAudioAudio →
  • Functions
    • Function StripDir$( path$ )
    • Function StripExt$( path$ )
    • Function StripAll$( path$ )
    • Function StripSlash$( path$ )
    • Function ExtractDir$( path$ )
    • Function ExtractExt$( path$ )
    • Function CurrentDir$()
    • Function RealPath$( path$ )
    • Function FileType:Int( path$ )
    • Function FileTime:Long( path$, timetype:Int=FILETIME_MODIFIED )
    • Function FileSize:Long( path$ )
    • Function FileMode:Int( path$ )
    • Function SetFileMode( path$,Mode:Int )
    • Function CreateFile:Int( path$ )
    • Function CreateDir:Int( path$,recurse:Int=False )
    • Function DeleteFile:Int( path$ )
    • Function RenameFile:Int( oldpath$,newpath$ )
    • Function CopyFile:Int( src$,dst$ )
    • Function CopyDir:Int( src$,dst$ )
    • Function DeleteDir:Int( path$,recurse:Int=False )
    • Function ChangeDir:Int( path$ )
    • Function ReadDir:Byte Ptr( path$ )
    • Function NextFile$( dir:Byte Ptr )
    • Function CloseDir( dir:Byte Ptr )
    • Function LoadDir$[]( dir$,skip_dots:Int=True )
    • Function OpenFile:TStream( url:Object,readable:Int=True,writeable:Int=True )
    • Function ReadFile:TStream( url:Object )
    • Function WriteFile:TStream( url:Object )
    • Function CloseFile( stream:TStream )
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson