how to retrieve a native path

How can I retrieve a native path start from a string like this “Macintosh HD:Users:john:Dropbox:program library:Xojo:document.doc” returned from an external function ?

Thanks in advances

Luciano

What you mean? The branch without the leaf like “Macintosh HD:Users:john:Dropbox:program library:Xojo” ?

Use string functions, find what you want and then left/right/split/join/whatever . :slight_smile:

To remove the last part you could use a function (method) like this (test please):

  Function RemoveLastMacPathPart(strPath as String) As String// "aaa:bbb:ccc" -> "aaa:bbb"
     Dim p() as string = split(strPath,":")
     if ubound(p)>0 then p.Remove(ubound(p))
     Return join(p,":")
  End Function

Dim f As FolderItem f = GetFolderItem("Macintosh HD:Users:john:Dropbox:program library:Xojo:document.doc").parent msgbox f.NativePath

Careful, the DropBox in there or the user name will vary with users.

thanks Rick and Michel.
I was meaning that Michel suggest.

Michel, I’ve tried but a NilObjectException was occurred … any idea ?

Did you change the path to the one from your external? Post your code for better help…

My proposed solution was problem focused and system independent, that means, solves the proposed problem (get a specific answer string from a source string) in any platform under any circumstances (processing in windows a string sent from OSX, processing a string from a source machine in a destination machine, etc). Michel’s method theoretically works supposing that you are using OSX and processing a real path from THIS current machine. It uses system calls, reads your disk and checks your current file system, If something gets incoherent, you could fall in NilObjectExceptions.

The path you cited as example contains two possible problems : it contains a dropbox path, which will not work if the machine is not connected, and it points to a user directory which is indicated under the name of the user instead of ~ (tilde).

You mention getting the original string from an external function. Would it be from another machine ? If this is the case, then unless the user does not share his folders, it will generate a NilObjectException.

Please describe what you are trying to achieve and if the path is on your local machine or somewhere else.

Is the path “Macintosh HD:Users:john:Dropbox:program library:Xojo:document.doc” on your machine or somewhere else ?

Your method indeed strips the last item.

It was pretty obvious from the “Macintosh HD” starting the string and the : separator that it was not Windows. Now if the path comes from another Mac it would explain the issue.

so, I try to explain better what I need to do.
I have an element of a dictionary that contains a path in this format “Macintosh HD:Users:john:Dropbox:program library:Xojo:document.doc” and I need to turn it into shell path format “/Users/lucianomonti/Dropbox/libreria programmi/document.doc” to be passed to a java function (should work in both mac osx and windows)

So your proposed code obviously works. :slight_smile:

this is an example path, forget Dropbox

Luciano, my proposal is that you write your conversion function, like I did for my example.

[quote=102973:@luciano monti]so, I try to explain better what I need to do.
I have an element of a dictionary that contains a path in this format “Macintosh HD:Users:john:Dropbox:program library:Xojo:document.doc” and I need to turn it into shell path format “/Users/lucianomonti/Dropbox/libreria programmi/document.doc” to be passed to a java function (should work in both mac osx and windows)[/quote]

As it stands, this path is for a specific Mac.

Please provide the exact path that generates the error, then. It is impossible to help you without specifics. The code I provided will work only on the specific machine where the folders indicated in the path work. So if you try it as is with a non existing folder, it will naturally generate a NilObjectException.

Can you give a real example ?

Dim f As FolderItem f = GetFolderItem("Macintosh HD:Users:john:Dropbox:program library:Xojo:document.doc").parent msgbox f.ShellPath

This will do the conversion. Make sure the original path is valid.

Michel is a local path.
Rick, I’ll try your solution

Michel, don’t forget he wants his code running even in Windows.

I did not write the solution for your case. I made just one explanation. The was the code to remove a leaf from the branch of a string with nodes separated by “:”.

Right. Notwidthstanding the issue of passing a local Macintosh nativepath to a remote Windows machine, the only issue is the separator, \ in Windows instead of /. So to get a path in Windows all he needs is to ReplaceAll(MacShellPath,"/","")…

Still, the issue will be access from the Windows machine to the Mac root…

I have made a small tool to insert the path in xojo. (OSX only)
use the Buttons (…) or drop a file to one of the labels.

ProjectFile