« MBS Xojo Plugins, ver… | Home | MBS @ FMTraining.TV -… »

MBS Plugin Advent calendar: 7 - Paths

Door 7 - Paths

Fact of the day
Did you know that you can easily copy the path of a file under Mac if you press the option key in the menu of the right mouse button at the same time? The menu will then show the entry as Copy...as pathname

Today it's all about how you can build paths in FileMaker with the help of the MBS FileMaker Plugin. We already got a little insight into this topic in the third door, where we created a path to a file on the desktop. The MBS FileMaker Plugin offers you some of these paths to special folders in your system. For example, you can use the Folders.UserDesktop function to determine the path to a user's desktop. Or you can determine the path to the temporary folder with Folders.UserTemporary. In this picture you can see the functions that are available for special folders.

In most cases, this is not enough as a path specification and we want to address a very specific file in this folder. To do this, we can assemble the path with MBS. For example, we have the function Path.AddPathComponent, which appends a component to the path in accordance with the operating system. Let's assume we want to address a file on the desktop called xyz.pdf, then our script can look like this:

Set Variable [ $Dektop ; Value: MBS("Folders.UserDesktop") ] 
Set Variable [ $Path ; Value: MBS("Path.AddPathComponent"; $Dektop; "xyz.pdf") ] 

First we get the path of the desktop with Folders.UserDesktop and append the file name as the last component.

If we already have a file path and want to know the last component of this file path, then we use the function Path.LastPathComponent.

Set Variable [ $Last ; Value: MBS("Path.LastPathComponent"; $Path) ] 

It is also possible, for example, if you have a file path from a file and want to write another file in the same folder as this file, then you can also remove the last path component by using the function Path.RemoveLastPathComponent to remove the last component. The functions I have used so far do not always need to have a file name as the last component, but the last component can also be a folder if it is the path to a folder.

In the path component we have further functions that can help you when working with paths.

If you need the file URL of a file, then you get the file URL back by specifying the path with the function Path.FilePathToFileURL. For the reverse path from a file URL to a path, you can use the Path.FileURLToFilePath function.

However, we can not only determine the file URL for a file, but can also return the FileMaker path for a native path and the other way round. For each direction we use the function Path.NativePathToFileMakerPath and Path.FileMakerPathToNativePath.

We also have something special for Windows users, because in Windows you can have a long form for paths and a short one. So that you can convert from one type to the other within FileMaker as you wish, we have the two functions Path.LongPath and Path.ShortPath.

I hope you enjoyed this door and we'll see each other tomorrow.


Monkeybread Software Logo with Monkey with Santa hat
6 👈 7 of 24 👉 8
07 12 23 - 12:53