Path.LastPathComponent
----------------------

Queries the last path component.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Path](component_Path.md) | [6.0](newinversion60.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Path.LastPathComponent"; Path ) 

**MBS**( **"Path.LastPathComponent";** /\* Queries the last path component. \*/  
**$Path**) /\* The native file path.e.g. "/Users/cs/Desktop" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Path | The native file path. | "/Users/cs/Desktop" |

### Result

Returns path or error.

### Description

Queries the last path component.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use [FileDialog](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
### Examples

Queries file name:

 MBS ( "Path.LastPathComponent"; "c:\\\\test.txt" )  
Get file name from container and add to folder path:

 Set Variable \[$name ; Value:GetAsText ( Container Batch Export::Test1 )\]  
Set Variable \[$name ; Value:GetValue($name ; 1)\]  
Set Variable \[$name ; Value:MBS ( "Path.LastPathComponent"; $name )\]  
Set Variable \[$dpath ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $FolderPath ; $name )\]  
Write container to temp file and launch:

 # get temp folder   
Set Variable \[$TempFolder ; Value:MBS ( "[Folders.SystemTemporary](FoldersSystemTemporary.md)" )\]  
\# and file name from container   
Set Variable \[$name ; Value:MBS ( "Path.LastPathComponent"; test::myContainer )\]  
\# add name to folder path   
Set Variable \[$TempPath ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $TempFolder ; $name )\]  
\# now write temp file   
Set Variable \[$r ; Value:MBS ( "[Files.WriteFile](FilesWriteFile.md)"; test::myContainer ; $TempPath )\]  
\# and launch file   
Set Variable \[$r ; Value:MBS ( "[Files.LaunchFile](FilesLaunchFile.md)"; $TempPath )\]  
### See also

- [Files.Launch](FilesLaunch.md)
- [Files.LaunchFile](FilesLaunchFile.md)
- [Files.WriteFile](FilesWriteFile.md)
- [MailComposer.AddAttachmentContainer](MailComposerAddAttachmentContainer.md)
- [MessageComposer.AddAttachmentContainer](MessageComposerAddAttachmentContainer.md)
- [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)
- [Path.RemoveLastPathComponent](PathRemoveLastPathComponent.md)
- [WIA.Image](WIAImage.md)
- [WIA.ImageCount](WIAImageCount.md)
- [WIA.ImageDialog](WIAImageDialog.md)

### Release notes

- **Version 15.2**
    - Fixed a bug in [Path.LastPathComponent](https://www.mbsplugins.eu/PathLastPathComponent.shtml) function where the last character got cut off.
- **Version 14.0**
    - Fixed an edge case with [Path.LastPathComponent](https://www.mbsplugins.eu/PathLastPathComponent.shtml) to return last path name, even if a slash is on the end of the path.

### Example Databases

- [CURL/Amazon S3/Amazon S3 Upload File](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Amazon%20S3/Amazon%20S3%20Upload%20File.shtml#3ScriptAnchor_)
- [Drag and Drop/DragTest Popover](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/DragTest%20Popover.shtml#3ScriptAnchor_)
- [Drag and Drop/DragTest](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/DragTest.shtml#3ScriptAnchor_)
- [DynaPDF/Merge PDFs](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Merge%20PDFs.shtml#7ScriptAnchor_)
- [iOS/Examples/iOS Email Sending](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/iOS/Examples/iOS%20Email%20Sending.shtml#6ScriptAnchor_)
- [iOS/Examples/iOS Message Sending](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/iOS/Examples/iOS%20Message%20Sending.shtml#6ScriptAnchor_)
- [iOS/Examples/Markup](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/iOS/Examples/Markup.shtml#1ScriptAnchor_)
- [Mac and iOS/PDFKit/PDFKit Print Documents](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/PDFKit/PDFKit%20Print%20Documents.shtml#12910FieldAnchor_)
- [Win Only/PhotoAcquire](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Win%20Only/PhotoAcquire.shtml#7ScriptAnchor_)
- [Win Only/Scanning/WIA Scan](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Win%20Only/Scanning/WIA%20Scan.shtml#9ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 15.2pr6](https://www.mbsplugins.de/archive/2025-04-25/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin Advent calendar: 7 - Paths](https://www.mbsplugins.de/archive/2023-12-07/MBS_Plugin_Advent_calendar_7_-/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.6pr1](https://www.mbsplugins.de/archive/2023-12-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Convert Office Files in FileMaker](https://www.mbsplugins.de/archive/2022-07-04/Convert_Office_Files_in_FileMa/monkeybreadsoftware_blog_filemaker)
- [Adding Drag and Drop receiver to a layout](https://www.mbsplugins.de/archive/2018-10-08/Adding_Drag_and_Drop_receiver_/monkeybreadsoftware_blog_filemaker)
- [Storing files for download on FileMaker Server with download URLs](https://www.mbsplugins.de/archive/2018-09-20/Storing_files_for_download_on_/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 6/2024, Seite 37](https://filemaker-magazin.de/neuigkeit/4277-Appetithappen-FMM_202406)
- [Ausgabe 6/2018, Seite 30 bis 31](https://filemaker-magazin.de/neuigkeit/4025-Appetithappen-FMM_201806)

This function is free to use.

Created 30th November 2015 , last changed 20th February 2024

  
[Path.FileURLToFilePath](PathFileURLToFilePath.md) - [Path.LongPath](PathLongPath.md)

[HTML Version](PathLastPathComponent.shtml)