Skip to content

Tools - File System Utilities

Detailed Documentation: Each class has its own detailed documentation with complete member descriptions and example code:


cToolsFso - File System Tools

Overview

Provides file path processing, auto-completion, directory creation, and other functionality.

Properties

Inst

Returns a Scripting.FileSystemObject instance.

vb
Public Inst As New Scripting.FileSystemObject

Example:

vb
' Use Inst to access FSO functionality
Dim Folder As Scripting.Folder
Set Folder = VBMAN.ToolsFso.Inst.GetFolder("C:\\MyFolder")

Dim File As Scripting.File
Set File = VBMAN.ToolsFso.Inst.GetFile("C:\\file.txt")

Path Processing

IsFullPath

Checks if a path is a full path (contains drive letter).

vb
Public Function IsFullPath(Path As String) As Boolean

Returns:

  • True - Is relative path (does not contain :\)
  • False - Is absolute path

Example:

vb
Debug.Print VBMAN.ToolsFso.IsFullPath("C:\\test.txt")  ' False (is full path)
Debug.Print VBMAN.ToolsFso.IsFullPath("test.txt")      ' True (is relative path)

AutoCompleteFullPath

Auto-completes to full path (relative path to absolute path).

vb
Public Function AutoCompleteFullPath(Path As String, Optional IsFile As Boolean) As String

Parameters:

ParameterTypeDescription
PathStringSource path
IsFileBooleanWhether it's a file path

Example:

vb
Dim FullPath As String
FullPath = VBMAN.ToolsFso.AutoCompleteFullPath("data\\config.ini")
' Result: C:\\MyApp\\data\\config.ini

ClearSpan

Cleans up extra slashes in the path, unified to backslash.

vb
Public Function ClearSpan(Path As String, Optional IsFile As Boolean) As String

Example:

vb
Debug.Print VBMAN.ToolsFso.ClearSpan("C:\\\\temp\\\\file.txt")
' Output: C:\\temp\\file.txt

Debug.Print VBMAN.ToolsFso.ClearSpan("C://temp//folder//", False)
' Output: C:\\temp\\folder\\

Directory Operations

AutoMakeDir

Automatically creates a directory (if it doesn't exist).

vb
Public Function AutoMakeDir(ByVal Path As String, Optional IsFile As Boolean) As String

Parameters:

ParameterTypeDescription
PathStringPath
IsFileBooleanWhether it's a file path (if True, extracts directory part)

Returns:

The created directory path.

Example:

vb
' Create directory
VBMAN.ToolsFso.AutoMakeDir "C:\\MyApp\\Logs"

' If file path, automatically extracts directory part and creates
VBMAN.ToolsFso.AutoMakeDir "C:\\MyApp\\Logs\\app.log", True
' Creates C:\\MyApp\\Logs directory

Application Path

AppPath

Gets the application path (automatically handles IDE and compiled path differences).

vb
Public Function AppPath(Optional ByVal Path As String) As String

Description:

  • IDE environment returns: App.Path & "\..\dist\EXE\"
  • Compiled returns: App.Path & "\"

Example:

vb
' IDE environment: C:\\MyProject\\..\\dist\\EXE\\
' Compiled: C:\\Program Files\\MyApp\\

Dim ConfigPath As String
ConfigPath = VBMAN.ToolsFso.AppPath("config.ini")
Debug.Print ConfigPath

File Name Processing

MakeNewFileFulPath

Generates a new file full path (adds suffix).

vb
Public Function MakeNewFileFulPath(FileSrc As String, AppendFix As String, Optional JoinStr As String = "_") As String

Parameters:

ParameterTypeDescription
FileSrcStringSource file path
AppendFixStringSuffix to add
JoinStrStringJoin string (default "_")

Example:

vb
Dim NewPath As String

NewPath = VBMAN.ToolsFso.MakeNewFileFulPath("C:\\file.txt", "backup")
' Output: file_backup.txt

NewPath = VBMAN.ToolsFso.MakeNewFileFulPath("C:\\data\\report.pdf", "2024", "-")
' Output: report-2024.pdf

cFileIO - Advanced File Operations (API Implementation)

Overview

Advanced file operations using Windows CreateFile API, supports large files (>2GB).

Properties

PropertyDescription
IsOpenWhether file is open (Boolean, read-only)
FilePathCurrent file path (String, read-only)
LastErrorLast error message (String, read-only)
FileSizeFile size (Currency, in bytes, read-only)
BufferSizeCurrent buffer byte count (Long, read-only)

File Open/Close

OpenFile

Opens a file, returns Me to support method chaining.

vb
Public Function OpenFile(ByVal FilePath As String, Optional ByVal AccessMode As String = "RW") As cFileIO

Parameters:

ParameterTypeDescription
FilePathStringFile path
AccessModeStringAccess mode: "R"=read-only, "W"=write-only, "RW"=read-write (default)

Example:

vb
' Open in read-only mode
VBMAN.FileIO.OpenFile "C:\\data.txt", "R"

' Open in read-write mode
VBMAN.FileIO.OpenFile "C:\\data.txt", "RW"

' Method chaining
Dim Content As String
Content = VBMAN.FileIO.OpenFile("C:\\data.txt").ReadData().ReturnText()

CloseFile

Closes the file.

vb
Public Sub CloseFile()

Example:

vb
VBMAN.FileIO.CloseFile

Buffer Operations

ClearBuffer

Clears the internal buffer.

vb
Public Function ClearBuffer() As cFileIO

SetBuffer

Fills the buffer with external byte array.

vb
Public Function SetBuffer(Data() As Byte) As cFileIO

Example:

vb
Dim Bytes() As Byte
Bytes = StrConv("Hello", vbFromUnicode)

VBMAN.FileIO.SetBuffer Bytes

AppendBuffer

Appends bytes to the buffer.

vb
Public Function AppendBuffer(Data() As Byte) As cFileIO

Example:

vb
Dim Bytes1() As Byte, Bytes2() As Byte
Bytes1 = StrConv("Hello", vbFromUnicode)
Bytes2 = StrConv(" World", vbFromUnicode)

VBMAN.FileIO.SetBuffer(Bytes1).AppendBuffer Bytes2

SetBufferText

Fills the buffer with string (default UTF-8).

vb
Public Function SetBufferText(ByVal Text As String, Optional ByVal CharSet As String = "UTF-8") As cFileIO

Example:

vb
VBMAN.FileIO.SetBufferText "Hello World", "UTF-8"

Data Reading

ReadData

Reads specified range of file into internal buffer.

vb
Public Function ReadData(Optional ByVal StartPos As Long = -1, Optional ByVal EndPos As Long = -1) As cFileIO

Parameters:

ParameterTypeDescription
StartPosLongStart position (0-based), -1 means from beginning
EndPosLongEnd position (0-based), -1 means to end

Example:

vb
' Read entire file
VBMAN.FileIO.OpenFile("C:\\data.txt").ReadData

' Read specified range
VBMAN.FileIO.OpenFile("C:\\data.txt").ReadData 0, 1023  ' Read first 1KB

' Method chaining to read and get text
Dim Text As String
Text = VBMAN.FileIO.OpenFile("C:\\data.txt").ReadData().ReturnText()

Data Return

ReturnText

Returns buffer content as text.

vb
Public Function ReturnText(Optional ByVal CharSet As String = "UTF-8") As String

Example:

vb
Dim Text As String
VBMAN.FileIO.OpenFile("C:\\utf8.txt").ReadData()
Text = VBMAN.FileIO.ReturnText("UTF-8")

ReturnBytes

Returns byte array (copy).

vb
Public Function ReturnBytes() As Byte()

Example:

vb
Dim Bytes() As Byte
VBMAN.FileIO.OpenFile("C:\\data.bin").ReadData()
Bytes = VBMAN.FileIO.ReturnBytes()

ReturnBase64

Returns Base64-encoded string.

vb
Public Function ReturnBase64() As String

Example:

vb
Dim Base64 As String
VBMAN.FileIO.OpenFile("C:\\image.png").ReadData()
Base64 = VBMAN.FileIO.ReturnBase64()

Data Writing

SaveData

Writes internal buffer to file.

vb
Public Function SaveData(Optional ByVal FilePath As String, Optional ByVal IsAppend As Boolean = False) As cFileIO

Parameters:

ParameterTypeDescription
FilePathStringTarget path, uses currently opened file if empty
IsAppendBooleanFalse=overwrite (default), True=append

Example:

vb
' Overwrite
VBMAN.FileIO.SetBufferText("Hello World").SaveData "C:\\output.txt"

' Append
VBMAN.FileIO.SetBufferText("New Line").SaveData "C:\\log.txt", True

' Write to currently opened file
VBMAN.FileIO.OpenFile("C:\\data.txt", "RW").SetBufferText("Content").SaveData

Complete Example

vb
Private Sub FileIODemo()
    ' Read text file
    Dim Content As String
    Content = VBMAN.FileIO.OpenFile("C:\\input.txt").ReadData().ReturnText()
    Debug.Print Content
    
    ' Read and convert
    Dim Base64 As String
    Base64 = VBMAN.FileIO.OpenFile("C:\\image.png").ReadData().ReturnBase64()
    
    ' Write file
    VBMAN.FileIO.SetBufferText("Hello World").SaveData "C:\\output.txt"
    
    ' Append content
    VBMAN.FileIO.SetBufferText("Line 1" & vbCrLf).SaveData "C:\\log.txt", True
    VBMAN.FileIO.SetBufferText("Line 2" & vbCrLf).SaveData "C:\\log.txt", True
    
    ' Copy file (chunked reading for large files)
    With VBMAN.FileIO
        .OpenFile "C:\\largefile.zip"
        Dim FileLen As Currency
        FileLen = .FileSize
        
        ' Read in 2MB chunks
        Dim Pos As Long
        For Pos = 0 To FileLen Step 2097152
            .ReadData Pos, Pos + 2097151
            .SaveData "C:\\copy.zip", True
        Next Pos
    End With
End Sub

cFileEx - Advanced File Operations (Open Statement Implementation)

Overview

File operations using VB native Open statement, with good compatibility, interface consistent with cFileIO.

Difference from cFileIO

FeaturecFileIOcFileEx
ImplementationCreateFile APIVB Open statement
Large file support>2GBLimited by VB
CompatibilityRequires Windows APINative VB, better compatibility
PerformanceHighModerate

Properties

Same as cFileIO:

  • IsOpen - Whether file is open
  • FilePath - Current file path
  • LastError - Last error message
  • FileSize - File size
  • BufferSize - Current buffer byte count

Methods

Same as cFileIO, with additional support:

SetBufferBase64

Fills the buffer with Base64 string.

vb
Public Function SetBufferBase64(ByVal Base64String As String) As cFileEx

Example:

vb
VBMAN.FileEx.SetBufferBase64 "SGVsbG8gV29ybGQ="

SetBufferHex

Fills the buffer with Hex string.

vb
Public Function SetBufferHex(ByVal HexString As String, Optional ByVal Separator As String = " ") As cFileEx

Example:

vb
VBMAN.FileEx.SetBufferHex "48 65 6C 6C 6F"
VBMAN.FileEx.SetBufferHex "48656C6C6F", ""  ' Without separator

SetBufferBinString

Fills the buffer with binary string.

vb
Public Function SetBufferBinString(ByVal BinString As String, Optional ByVal Separator As String = " ") As cFileEx

Example:

vb
VBMAN.FileEx.SetBufferBinString "01001000 01100101 01101100 01101100 01101111"

ReturnHex

Returns Hex-encoded string.

vb
Public Function ReturnHex(Optional ByVal Separator As String = " ") As String

Example:

vb
VBMAN.FileEx.OpenFile("C:\\data.bin").ReadData()
Debug.Print VBMAN.FileEx.ReturnHex(" ")  ' Output: 48 65 6C 6C 6F
Debug.Print VBMAN.FileEx.ReturnHex("")   ' Output: 48656C6C6F

ReturnBinString

Returns binary string.

vb
Public Function ReturnBinString(Optional ByVal Separator As String = " ") As String

Example:

vb
Debug.Print VBMAN.FileEx.ReturnBinString(" ")  ' Output: 01001000 01100101...

cToolsStream - Stream File Operations

Overview

File stream operations based on ADODB.Stream, supporting line-by-line reading/writing and multiple encodings.

Properties

PropertyTypeDescription
InstADODB.StreamStream instance
LastErrorStringLast error message
UseLineBooleanWhether line-by-line mode is enabled
LineDatacCollectionLine data collection
LineNumberLongCurrent line number

Methods

UseLineMode

Sets whether to enable line-by-line read/write mode (method chaining).

vb
Public Function UseLineMode(v As Boolean) As cToolsStream

Example:

vb
VBMAN.ToolsStream.UseLineMode(True)

LoadFileAsText

Loads a text file.

vb
Public Function LoadFileAsText(ByVal FileName As String, Optional ByVal CharSet As String = "UTF-8") As String

Example:

vb
Dim Content As String
Content = VBMAN.ToolsStream.LoadFileAsText("test.txt", "UTF-8")

SaveFileAsText

Saves a text file.

vb
Public Function SaveFileAsText(ByVal FileName As String, Optional Data As Variant, Optional ByVal CharSet As String = "UTF-8") As Boolean

Example:

vb
' Save data directly
VBMAN.ToolsStream.SaveFileAsText "output.txt", "Hello World", "UTF-8"

' Use line mode to save
VBMAN.ToolsStream.UseLineMode(True)
VBMAN.ToolsStream.WriteLine "Line 1"
VBMAN.ToolsStream.WriteLine "Line 2"
VBMAN.ToolsStream.SaveFileAsText "output.txt", , "UTF-8"

LoadFileAsBinary

Loads file as binary.

vb
Public Function LoadFileAsBinary(ByVal Path As String, OutData() As Byte) As Boolean

Example:

vb
Dim Data() As Byte
VBMAN.ToolsStream.LoadFileAsBinary "image.png", Data

SaveFileAsBinary

Saves file as binary.

vb
Public Function SaveFileAsBinary(ByVal Path As String, OutData() As Byte) As Boolean

Example:

vb
Dim Data() As Byte
' ... fill Data
VBMAN.ToolsStream.SaveFileAsBinary "output.bin", Data

ReadLine

Reads a line (requires line mode enabled).

vb
Public Function ReadLine(Optional ByVal Line As Long) As String

Parameters:

ParameterTypeDescription
LineLongSpecify line number, 0 means current line

Example:

vb
' Read file line by line
With VBMAN.ToolsStream.UseLineMode(True)
    .LoadFileAsText "log.txt", "UTF-8"
    
    Dim Line As String
    Line = .ReadLine(1)  ' Read line 1
    Debug.Print Line
    
    Line = .ReadLine()   ' Read next line (auto increment)
    Debug.Print Line
End With

WriteLine

Writes a line (requires line mode enabled).

vb
Public Function WriteLine(Text As String, Optional ByVal Line As Long) As Boolean

Example:

vb
' Write file line by line
With VBMAN.ToolsStream.UseLineMode(True)
    .WriteLine "First line content"
    .WriteLine "Second line content"
    .WriteLine "Third line content", 10  ' Write to line 10
    .SaveFileAsText "output.txt", , "UTF-8"
End With

Complete Example

vb
Private Sub FileOperationsDemo()
    ' ========== cToolsFso Examples ==========
    
    ' Create directory
    VBMAN.ToolsFso.AutoMakeDir "C:\\MyApp\\Logs"
    
    ' Get application path
    Dim AppPath As String
    AppPath = VBMAN.ToolsFso.AppPath("config.ini")
    
    ' Generate backup file name
    Dim BackupName As String
    BackupName = VBMAN.ToolsFso.MakeNewFileFulPath("report.pdf", "backup")
    
    ' ========== cFileIO Examples ==========
    
    ' Read large file
    Dim LargeFileContent As String
    With VBMAN.FileIO
        .OpenFile "C:\\largefile.bin"
        LargeFileContent = .ReadData().ReturnBase64()
    End With
    
    ' Write file
    VBMAN.FileIO.SetBufferText("Hello World").SaveData "C:\\test.txt"
    
    ' ========== cFileEx Examples ==========
    
    ' Hex operations
    VBMAN.FileEx.SetBufferHex "48 65 6C 6C 6F"
    VBMAN.FileEx.SaveData "C:\\hex_test.bin"
    
    ' ========== cToolsStream Examples ==========
    
    ' Process config file line by line
    With VBMAN.ToolsStream.UseLineMode(True)
        .LoadFileAsText "config.ini", "UTF-8"
        
        Dim i As Long
        For i = 1 To 10
            Debug.Print "Line " & i & ": " & .ReadLine(i)
        Next i
    End With
End Sub

VB6 and LOGO copyright of Microsoft Corporation