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.
- 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
1 | fso.GetFileName( path ) |
path
The path for which the file name or folder name is to be provided.
VBA GetFileName Examples
1 2 3 4 5 6 7 | 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" |