Using SMB styled paths with Troi File Plug-in

Troi File Plug-in 13 added support for using SMB styled paths as parameters for any file or folder path (on macOS only).

For a path to a text file you can use for example: smb://192.168.178.12/myShare/MainFolder/subFolder/mytext.txt  Note that you need to mount the SMB share first (once). For this you can use the TrFile_MountDisk function, like this:

Set Variable [ $SMBShareURL ; "smb://192.168.178.12/" ]
Set Variable [ $SMBShareName ; "myShare" ]
 
# Mount the SMB disk:
Set Variable [ $ErrorCode ; TrFile_MountDisk( "-Unused";""; $SMBShareURL ; $SMBShareName ; 
                                                            $UserName; $Password ) ]

When no error occurs the SMB disk is mounted. You can now use the SMB styled path as parameter in your scripts.  For example to get the contents of the file hello.txt, add this to a script:

# Getting the contents of a file on a SMB Disk
# --------------------------------------------
 
# Set your SMB url and share name into variables:
Set Variable [ $SMBShareURL ; "smb://192.168.178.12/" ]
Set Variable [ $SMBShareName ; "myShare" ]
 
# Build the total SMB path:
Set Variable [ $SMBPathToFile; $SMBShareURL & "/" & $SMBShareName "/MainFolder/hello.txt"]
 
# Now get the contents:
Set Variable [ $TheContents; TrFile_GetContents( "-unused" ; $SMBPathToFile )]

Adding a port number

You can add a port number too if the SMB server is available on a different port. In that case you need to mount the SMB share with that port number (once), like this:

# Set the port number, SMB url and share name into variables:
Set Variable [ $SMBPortNumber ; "678" ]
Set Variable [ $SMBShareURL ; "smb://192.168.178.12" & ":" & $SMBPortNumber & "/" ]
# $SMBShareURL is now "smb://192.168.178.12:678/"
Set Variable [ $SMBShareName ; "myShare" ]
 
# Mount the disk:
Set Variable [ $ErrorCode ; TrFile_MountDisk( "-unused"; ""; $SMBShareURL ; $SMBShareName ; 
                                                             $UserName; $Password ) ]

Now you can use the SMB styled path with the port number as parameter. Again to get the contents of the file hello.txt add these steps to a script:

# Getting the contents of a file on a SMB Disk (with a custom port number)
# ------------------------------------------------------------------------
Set Variable [ $SMBPortNumber ; "678" ]
Set Variable [ $SMBShareURL ; "smb://192.168.178.12" & ":" & $SMBPortNumber & "/" ]
# $SMBShareURL is now "smb://192.168.178.12:678/"
Set Variable [ $SMBShareName ; "myShare" ]
Set Variable [ $SMBPathToFile; $SMBShareURL & "/" & $SMBShareName "/MainFolder/hello.txt"]
 
# Now get the contents into a variable:
Set Variable [ $TheContents; TrFile_GetContents( "-unused" ; $SMBPathToFile )]

Where can you use SMB paths

You can use SMB styled paths for files and folders.  Also you can use it in any script step or function of Troi File that has a path parameter.