Path.AddPathComponent
---------------------

Adds a new 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.AddPathComponent"; Path; Component... ) 

**MBS**( **"Path.AddPathComponent";** /\* Adds a new path component. \*/  
**$Path**; /\* The native file path.e.g. "/Users/cs/Desktop" \*/   
**$Component...**) /\* The new path component.e.g. "Hello" \*/ 

### Parameters

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

### Result

Returns path or error.

### Description

Adds a new path component.  
The path provided as parameter does not need to end with a slash or backslash.  
  
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.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Component parameter as often as you need.  
### Examples

Adds a path component to a path:

 MBS ( "Path.AddPathComponent"; "/Users/cs/Desktop"; "Hello" )  
Adds a file name:

 MBS ( "Path.AddPathComponent"; "/Users/cs/Desktop/"; "test.txt" )  
Adds a file path on Windows:

 MBS ( "Path.AddPathComponent"; "c:\\\\Test"; "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](PathLastPathComponent.md)"; $name )\]  
Set Variable \[$dpath ; Value:MBS ( "Path.AddPathComponent"; $FolderPath ; $name )\]  
Create folder on Desktop:

 Set Variable \[$folder ; Value:MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" )\]  
If \[IsEmpty(Container Export::Name )\]  
 Set Field \[Container Export::Name ; "Record " &amp; Get(RecordID)\]  
End If  
Set Variable \[$path ; Value:MBS ( "Path.AddPathComponent"; $folder ; Container Export::Name )\]  
Set Variable \[$r ; Value:MBS ("[Files.CreateDirectory](FilesCreateDirectory.md)"; $path )\]  
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](PathLastPathComponent.md)"; test::myContainer )\]  
\# add name to folder path   
Set Variable \[$TempPath ; Value:MBS ( "Path.AddPathComponent"; $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 )\]  
Add multiple path componennts:

 MBS ( "Path.AddPathComponent"; "/Users/cs/Desktop"; "Hello"; "World"; "test" )  
<small>  
Example result: /Users/cs/Desktop/Hello/World/test</small>Export a container to desktop:

 # get path stored in the container field   
Set Variable \[ $ContainerPath ; Value: GetAsText ( Contacts::Photo Container ) \]   
\# get the file name portion   
Set Variable \[ $ContainerName ; Value: MBS ( "[Path.LastPathComponent](PathLastPathComponent.md)"; $ContainerPath ) \]   
\# take a folder on the computer, e.g. desktop   
Set Variable \[ $DesktopFolder ; Value: MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" ) \]   
\# build path with file name on that folder   
Set Variable \[ $FilePath ; Value: MBS ( "Path.AddPathComponent"; $DesktopFolder ; $ContainerName ) \]   
\# and export the content of container to that path   
Set Variable \[ $r ; Value: MBS ( "[Container.WriteFile](ContainerWriteFile.md)"; Contacts::Photo Container; $FilePath ) \]  
Import all files in a folder:

 # list files in a folder   
Set Variable \[ $r ; Value: MBS ("[Files.List](FilesList.md)"; $FolderPath ) \]   
  
\# loop over the files   
Set Variable \[ $count ; Value: ValueCount ( $r ) \]   
Set Variable \[ $index ; Value: 0 \]   
If \[ $count &gt;0 \]   
 Loop  
 # build path  
 Set Variable \[$fileName ; GetValue ( $r ; $index +1 )\]  
 Set Variable \[$filePath ; Value: MBS ( "Path.AddPathComponent"; $FolderPath ; $fileName )\]  
 Set Variable \[$fileData ; Value: MBS ("[Container.ReadFile](ContainerReadFile.md)"; $filePath )\]  
  
 # create record for new file  
 New Record/Request  
 Set Field \[MyData::Container ; $fileData \]  
 Set Field \[MyData::Name ; $fileName \]   
 Commit Records/Requests \[ With dialog: Off \]   
  
 Set Variable \[ $index ; Value: $index + 1 \]   
 Exit Loop If \[ $index = $count \]   
 End Loop  
End If  
### See also

- [Path.LastPathComponent](PathLastPathComponent.md)
- [Text.WriteTextFile](TextWriteTextFile.md)
- [Trace.SetErrorsOnly](TraceSetErrorsOnly.md)
- [WebView.PrintToFile](WebViewPrintToFile.md)
- [WIA.ImageDialog](WIAImageDialog.md)
- [WordFile.ReplaceTag](WordFileReplaceTag.md)
- [XL.Book.DeleteSheet](XLBookDeleteSheet.md)
- [XL.Book.SaveToFile](XLBookSaveToFile.md)
- [XL.Sheet.RemoveRow](XLSheetRemoveRow.md)
- [ZipFile.CompressFiles](ZipFileCompressFiles.md)

### Release notes

- **Version 15.0**
    - Fixed [Path.AddPathComponent](https://www.mbsplugins.eu/PathAddPathComponent.shtml) function for Windows to automatically use slash or backslash depending on what the path has already.
- **Version 9.4**
    - Changed [Path.AddPathComponent](http://www.mbsplugins.eu/PathAddPathComponent.shtml) to accept multiple parameters.

### Example Databases

- [CURL/Email/Email Parser and Preview](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Email%20Parser%20and%20Preview.shtml#2ScriptAnchor_)
- [CURL/Email/IMAP Email](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/IMAP%20Email.shtml#6ScriptAnchor_)
- [DynaPDF/RenderJob](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/RenderJob.shtml#1ScriptAnchor_)
- [GraphicsMagick/Create GIF](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Create%20GIF.shtml#1ScriptAnchor_)
- [GraphicsMagick/Create Multi Tiff](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Create%20Multi%20Tiff.shtml#2ScriptAnchor_)
- [Mac only/Icon and QuickLook/QuickLook Preview Panel](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20only/Icon%20and%20QuickLook/QuickLook%20Preview%20Panel.shtml#3ScriptAnchor_)
- [Saxon/Saxon ZUGFeRD Validation](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20ZUGFeRD%20Validation.shtml#1ScriptAnchor_)
- [Third Party/FileMaker Snippet Storage](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Third%20Party/FileMaker%20Snippet%20Storage.shtml#19CustomFunctionAnchor_)
- [WebViewer/Custom WebView](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/WebViewer/Custom%20WebView.shtml#7ScriptAnchor_)
- [Win Only/Snippets for Windows](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Win%20Only/Snippets%20for%20Windows.shtml#11ScriptAnchor_)

### Blog Entries

- [Create PDF/UA with DynaPDF in FileMaker](https://www.mbsplugins.de/archive/2026-05-27/Create_PDFUA_with_DynaPDF_in_F/monkeybreadsoftware_blog_filemaker)
- [Validate electronic invoices with Saxon](https://www.mbsplugins.de/archive/2026-03-20/Validate_electronic_invoices_w/monkeybreadsoftware_blog_filemaker)
- [Visualize electronic invoices with Saxon](https://www.mbsplugins.de/archive/2026-03-16/Visualize_electronic_invoices_/monkeybreadsoftware_blog_filemaker)
- [From speech to text with FileMaker and MBS](https://www.mbsplugins.de/archive/2025-05-01/From_speech_to_text_with_FileM/monkeybreadsoftware_blog_filemaker)
- [Validate electronic invoices with Saxon](https://www.mbsplugins.de/archive/2025-02-18/Validate_electronic_invoices_w/monkeybreadsoftware_blog_filemaker)
- [Visualize electronic invoices with Saxon](https://www.mbsplugins.de/archive/2025-02-17/Visualize_electronic_invoices_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 23 - Printing a PDF](https://www.mbsplugins.de/archive/2024-12-23/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 18 - ics-Files](https://www.mbsplugins.de/archive/2024-12-18/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 17 - User Notifications](https://www.mbsplugins.de/archive/2024-12-17/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 15 - vCard QR](https://www.mbsplugins.de/archive/2024-12-15/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 2/2025, Seite 24](https://filemaker-magazin.de/neuigkeit/4286-Appetithappen-FMM_202502)
- [Ausgabe 5/2024, Seite 29](https://filemaker-magazin.de/neuigkeit/4272-Appetithappen-FMM_202405)
- [Ausgabe 3/2024, Seite 31](https://filemaker-magazin.de/neuigkeit/4263-Appetithappen-FMM_202403)
- [Ausgabe 4/2023, Seite 37 bis 39](https://filemaker-magazin.de/neuigkeit/4233-Appetithappen-FMM_202304)
- [Ausgabe 6/2022, Seite 14](https://filemaker-magazin.de/neuigkeit/4206-Appetithappen-FMM_202206)
- [Ausgabe 6/2021, Seite 21](https://filemaker-magazin.de/neuigkeit/4165-Appetithappen-FMM_202106)
- [Ausgabe 4/2020, Seite 34](https://filemaker-magazin.de/neuigkeit/4103-Appetithappen-FMM_202004)
- [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

  
[PageSetupDialog.SetScalingFactor](PageSetupDialogSetScalingFactor.md) - [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md)

[HTML Version](PathAddPathComponent.shtml)