GetFilenamePart()

Summary

Gets a part of a file path or folder name.

Syntax

parts = GetFilenamePart(string pathname, string whatpart)

Argument Contents
pathname A path to a file or folder
whatpart The part of the filepath or folder name that should be returned. Supported items and returned values are: "Drive", "Path", "Name", "Title", "Extension", "Parent Folder". See below for the returned values for each option.

Returns

A string with the file part requested.

Whatpart Returned value
Drive Returns the path drive (e.g. "C:" )
Path Returns the path or folder name (e.g. "c:\\Program Files\\Maptitude 2021\\" )
Name Returns the filename and extension (e.g. "mapt.exe" )
Title Returns the filename without the extension (e.g. "mapt" )
Extension Returns the filename extension (e.g. ".exe" )
Parent Folder Returns the parent folder (e.g. "c:\\Program Files\\" )

Example

filepath = "c:\\MySubfolder\\MyFilename.txt"
ext = GetFilenamePart(filepath , "Extension")
path = GetFilenamePart(filepath , "Path")

See Also

Function Summary
GetLongPathName() Returns the full, long path name for a file
GetShortPathName() Returns the short path name for a file
SplitPath() Splits a path and filename into its component parts.