Files and Folders in MS Access – A Large Function Toolbox (No References)

Read and write files, create, copy, move and check folders – again and again. This module bundles around 70 tasks into clearly named, consistent functions (File* / Folder* / Path*): pure late binding, 32/64-bit, silent error behavior and UTF-8. Just import one module – done.

If you work with VBA and Access, you know the drill: read and write files, create folders, copy, move, check whether something exists or is writable – over and over. This module bundles all these tasks into clearly named, consistent functions that combine elegantly.

What makes them special?

A consistent naming and return scheme (File* / Folder* / Path*), pure late binding (no references required, 32/64-bit), silent error behavior (a defined error value instead of dialogs) and UTF-8 capable reading and writing. Every function is commented and validates its inputs.

Return and error convention: actions (Create/Write/Delete/Copy/Move) return Boolean (error = False), string queries "", number queries -1, lists an empty array. Errors are silent by default; with FilesFolderVerbose True real errors are shown via the central ErrBox.

Group A – Path decomposition (pure string, no disk access)

Function Description Signature
FileName File name incl. extension, e.g. β€œreport.txt”. FileName(sPath) β†’ String
FileBaseName File name without extension, e.g. β€œreport”. FileBaseName(sPath) β†’ String
FileSuffix Extension lowercase, without dot, e.g. β€œtxt”. FileSuffix(sPath) β†’ String
FileFolder Parent folder, without trailing backslash. FileFolder(sPath) β†’ String
FileExtChange Swap the extension (report.txt β†’ report.pdf). FileExtChange(sPath, sNewExt) β†’ String
PathCombine Join folder and name with exactly one backslash. PathCombine(sFolder, sName) β†’ String
PathDrive Drive (β€œC:”) or UNC root. PathDrive(sPath) β†’ String
PathIsAbsolute Is the path absolute (drive or UNC)? PathIsAbsolute(sPath) β†’ Boolean
PathNormalize Cleans separators, double backslashes, resolves ./... PathNormalize(sPath) β†’ String

Group B – File operations (disk access)

Function Description Signature
FileExists Checks whether a file exists. FileExists(sPath) β†’ Boolean
FileCreate Creates an empty file. FileCreate(sPath, [bolOverwrite=False]) β†’ Boolean
FileRead Reads the entire content of a text file. FileRead(sPath, [sCharset="UTF-8"]) β†’ String
FileReadLines Reads the file as an array of lines. FileReadLines(sPath, [sCharset="UTF-8"]) β†’ Variant
FileWrite Writes text (UTF-8 with BOM). FileWrite(sPath, sContent, [bolOverwrite=True], [sCharset="UTF-8"]) β†’ Boolean
FileWriteUtf8 Writes UTF-8, BOM optional – ideal for clean HTML. FileWriteUtf8(sPath, sContent, [bolBom=False], [bolOverwrite=True]) β†’ Boolean
FileWriteLines Writes an array line by line. FileWriteLines(sPath, vLines, [bolOverwrite=True], [sCharset="UTF-8"]) β†’ Boolean
FileAppend Appends text encoding-safely. FileAppend(sPath, sContent, [sCharset="UTF-8"]) β†’ Boolean
FileDelete Deletes permanently (bypassing the recycle bin). FileDelete(sPath) β†’ Boolean
FileCopy Copies a file. FileCopy(sSource, sDest, [bolOverwrite=False]) β†’ Boolean
FileMove Moves or renames a file. FileMove(sSource, sDest) β†’ Boolean
FileSize Size in bytes (> 2 GB β†’ -1). FileSize(sPath) β†’ Long
FileDateModified β€œLast modified” date. FileDateModified(sPath) β†’ Date
FileCanRead Real read test. FileCanRead(sPath) β†’ Boolean
FileCanWrite Real write test (without changing content). FileCanWrite(sPath) β†’ Boolean
FileSetReadOnly Sets/removes the ReadOnly attribute. FileSetReadOnly(sPath, bolReadOnly) β†’ Boolean
FileBackup Timestamped backup copy, returns its path. FileBackup(sPath) β†’ String
FileTrash Moves a file to the recycle bin (SHFileOperation). FileTrash(sPath) β†’ Boolean
FileIsLocked Is the file locked by another process? FileIsLocked(sPath) β†’ Boolean
FileWait Waits until the file exists and is unlocked. FileWait(sPath, [lngTimeoutMs=5000], [bolUntilUnlocked=True]) β†’ Boolean
FileTouch Creates the file or updates only its modified date. FileTouch(sPath) β†’ Boolean
FileLineCount Counts the lines of a text file. FileLineCount(sPath) β†’ Long
FilesEqual Compares two files (size, then byte by byte). FilesEqual(sPathA, sPathB) β†’ Boolean
FileReplaceInText Replaces text in a file. FileReplaceInText(sPath, sOld, sNew) β†’ Boolean
FileSizeFormat Formats bytes readably, e.g. β€œ1.4 MB”. FileSizeFormat(dblBytes, [iDecimals=1]) β†’ String
LogWrite Appends a log line (timestamp + level + message), text or CSV. LogWrite(sPath, sMessage, [eLevel=logINFO], [bolCsv=False]) β†’ Boolean

Group C – Folder operations (disk access)

Function Description Signature
FolderExists Checks whether a folder exists. FolderExists(sPath) β†’ Boolean
FolderCreate Creates a folder, including missing intermediate folders. FolderCreate(sPath) β†’ Boolean
FolderRead List of files (optionally recursive), full paths. FolderRead(sPath, [sPattern="*"], [bolSubfolders=False]) β†’ Variant
FolderSubfolders List of direct subfolders. FolderSubfolders(sPath) β†’ Variant
FolderCount Number of files at the top level. FolderCount(sPath, [sPattern="*"]) β†’ Long
FolderSubfolderCount Number of direct subfolders. FolderSubfolderCount(sPath) β†’ Long
FolderDelete Deletes permanently (without Recursive only if empty). FolderDelete(sPath, [bolRecursive=False]) β†’ Boolean
FolderTrash Moves a folder incl. content to the recycle bin. FolderTrash(sPath) β†’ Boolean
FolderEmpty Deletes the content, keeps the folder. FolderEmpty(sPath) β†’ Boolean
FolderSize Total size in bytes incl. subfolders. FolderSize(sPath) β†’ Long
FolderDateModified β€œLast modified” date. FolderDateModified(sPath) β†’ Date
FolderCanRead Real read test (enumerates the folder). FolderCanRead(sPath) β†’ Boolean
FolderCanWrite Real write test (creates/deletes a test file). FolderCanWrite(sPath) β†’ Boolean
FolderCopy Copies a folder incl. content. FolderCopy(sSource, sDest, [bolOverwrite=False]) β†’ Boolean
FolderMove Moves or renames a folder. FolderMove(sSource, sDest) β†’ Boolean
FolderNewestFile The most recently modified file of a folder. FolderNewestFile(sPath, [sPattern="*"]) β†’ String
FolderZip Packs the folder content into a .zip (Windows shell). FolderZip(sFolder, sZip, [bolOverwrite=False]) β†’ Boolean
FolderUnzip Extracts a .zip into a folder. FolderUnzip(sZip, sFolder, [bolOverwrite=False]) β†’ Boolean
FolderTree Folder tree with connecting lines (Explorer look) as string, to the Immediate Window or a file. FolderTree(sPath, [eTarget=treeString], [sFile], [bolFilesToo=True], [bolFileSize=False], [bolAscii=False], [bolSummary=False], [lngMaxDepth=0]) β†’ String

Group D – File AND folder combined

Function Description Signature
PathExists Does the path exist as a file OR folder? PathExists(sPath) β†’ Boolean
PathType Returns β€œFile”, β€œFolder” or β€œβ€œ. PathType(sPath) β†’ String
PathCopy Copies a file or folder (depending on type). PathCopy(sSource, sDest, [bolOverwrite=False]) β†’ Boolean
PathMove Moves a file or folder. PathMove(sSource, sDest) β†’ Boolean
PathRename Renames (stays in the same folder). PathRename(sPath, sNewName) β†’ Boolean
PathTemp A unique, not-yet-existing path in TEMP. PathTemp([sSuffix=".tmp"]) β†’ String

Group E – System integration

Function Description Signature
FileOpen Opens a file with the associated default program. FileOpen(sPath) β†’ Boolean
FolderOpen Opens a folder in Windows Explorer. FolderOpen(sPath) β†’ Boolean
FileShowInFolder Opens Explorer with the file already selected. FileShowInFolder(sPath) β†’ Boolean

Group F – Drives, special folders & dialogs

Function Description Signature
DriveExists Checks whether a drive exists. DriveExists(sDrive) β†’ Boolean
DriveFreeSpace Free space in bytes. DriveFreeSpace(sDrive) β†’ Double
SpecialFolder Known folder by string (Temp, Desktop, Documents …). SpecialFolder(sName) β†’ String
SystemFolder Known folder by enum – type-safe and more extensive. SystemFolder(eFolder) β†’ String
FilePicker File-open dialog, returns the selected file. FilePicker([sFilter], [sTitle], [sInitialFolder]) β†’ String
FileSaveDialog Windows Save-As dialog (does not create the file). FileSaveDialog([sFilter], [sTitle], [sInitialFolder], [sDefaultName], [sDefaultExt]) β†’ String
FolderPicker Folder-selection dialog. FolderPicker([sTitle], [sInitialFolder]) β†’ String

Configuration & central message

Function Description Signature
FilesFolderVerbose Switches between silent and verbose mode (errors via ErrBox). FilesFolderVerbose(bolOn)
ErrBox Central error display (used internally in verbose mode). ErrBox(errNo, errDesc, [errMod], [errProc], [errInfo])

Enumerations

eSystemFolder – known system folders for SystemFolder(): user profile (sfProfile, sfDesktop, sfDocuments, sfDownloads, sfPictures, sfMusic, sfVideos, sfFavorites, sfRecent, sfSendTo), application data (sfAppData, sfLocalAppData, sfProgramData), start menu/shared (sfStartMenu, sfPrograms, sfStartup, sfCommonStartMenu, sfCommonDesktop, sfPublic), system (sfWindows, sfSystem, sfProgramFiles, sfProgramFilesX86, sfFonts, sfTemp, sfRecycleBin) and sfApp (folder of the running Access DB).

eLogLevel – severity for LogWrite(): logINFO, logWARN, logFAIL, logSUCCESS, logDONE. Text format 2026-07-15 14:30:00 [INFO ] message (level padded to 7 characters), CSV 2026-07-15 14:30:00;INFO;message.

Deployment & integration

Just import the module modHelper_FilesFolder – done. No references, no setup. In exactly two places the module uses a Win32 API (via conditional compilation #If VBA7, 32/64-bit safe, no reference): SHFileOperation for the recycle bin (FileTrash/FolderTrash) and GetSaveFileName for the Save-As dialog (FileSaveDialog). The central ErrBox is included.

Quick test: RunTests

The module modHelper_FilesFolder_TESTING is purely a development aid. RunTests asks for a base path via InputBox, creates a test structure below it and calls every function section by section. After each step the result appears as β€œlabel β†’ result” in the Immediate Window; expected negative results are marked β€œexpected:”. At the end it cleans up after a confirmation. Not needed for operational use.

The test form frmFilesFolder_TESTING

Figure 1: The interactive test form.

Besides RunTests there is the interactive test form. It lists all functions in a combo box, automatically creates a sandbox test folder under %TEMP% on opening (with example files) and deletes it on closing. For each function it shows the full description (purpose, parameters, return, signature) at the top and runs a safe demo below. Via the β€œRun” field you can execute your own call; for data-changing functions a safety prompt appears first. β€œShow VBE” jumps straight to the source code.

All calls of the form work exclusively in the sandbox test folder under %TEMP% – never on real data.

What you really need in production: only one module, modHelper_FilesFolder. It contains all functions and the ErrBox, works via late binding – no references, no setup, 32/64-bit. Not needed (development aids only): modHelper_FilesFolder_TESTING, the class clsFilesFolder and the form frmFilesFolder_TESTING.

Conclusion

With these functions your file and folder handling in Access becomes faster, more consistent and more robust – less boilerplate, fewer sources of error, better readability. The example database contains the module and form, ready to import.

Download

A large VBA toolbox for MS Access with around 70 functions for files and folders – a consistent naming scheme, late binding, 32/64-bit, silent error behavior and UTF-8.

βœ• Newsletter

Newsletter