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 FileSystemObject Methods
- BuildPath
- CopyFile
- CopyFolder
- CreateFolder
- CreateTextFile
- DeleteFile
- DeleteFolder
- DriveExists
- FileExists
- FolderExists
- GetAbsolutePathName
- GetBaseName
- GetDrive
- GetDriveName
- GetExtensionName
- GetFile
- GetFileName
- GetFolder
- GetParentFolderName
- GetSpecialFolder
- GetTempName
- MoveFile
- MoveFolder
- OpenTextFile
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"