I am stuck trying to convert a Mac path to a POSIX path in Python. I want to convert something like this:
'Main HD:Users:sasha:Documents:SomeText.txt'
:
'/Users/sasha/Documents/SomeText.txt'
I know that I could just split the string into a list and then reconnect with the correct delimiter. But I believe that there should be a much more elegant solution that I am missing, perhaps using the python modules "macpath" or "os.path". However, I was not able to define a function inside these modules that would do the conversion trick of the two formats.
Another problem with a simple string manipulation solution is that if I have multiple HDs, then a simple solution will not work. For instance:
If you have a path, for example:
'Extra HD:SomeFolder:SomeOtherText.txt'
we would like this transformation to be:
'/Volumes/Extra HD/SomeFolder/SomeOtherText.txt'
Not for:
'/SomeFolder/SomeOtherText.txt'
source share