VBA GetFileName

The FileSystemObject VBA GetFileName function returns the last component of a file or folder path except for the drive name. If a file path if given this will return just the file name. If a folder path is provided this will return the folder name.

VBA GetFileName Syntax

fso.GetFileName( path )

path
The path for which the file name or folder name is to be provided.

VBA GetFileName Examples

Set fso = CreateObject("Scripting.FileSystemObject")

fso.GetFileName("C:\Src") 'Result: "Src"

fso.GetFileName("C:\Src\") 'Result: "Src"

fso.GetFileName("C:\Src\Hello.txt") 'Result: "Hello.txt"