[Pythonmac-SIG] os.path.join()

Just van Rossum just@letterror.com
Fri, 5 Mar 1999 13:47:15 +0100


At 5:37 PM -0800 3/4/99, Chris Walker wrote:
>I'm writing a program to copy many files of certain types to a network volume.
>I'm using os.path.join() to attach a directory to the front of the absolute
>paths of the files to mimic the directory structure on the network volume.
>
>The net volume is mounted as 'cwalker', and the drive is called 'Macintosh
>HD'.
>
>>>> import os
>>>> os.path.join('cwalker', 'Macintosh HD:Devel:Python:myscript')
>'Macintosh HD:Devel:Python:myscript'
>
>I'm using string.join() to get around it for now, but os.path.join() seems
>like
>the cross-platform, 'right' way to do it.
>
>What I'd like it to return is 'cwalker:Macintosh
>HD:Devel:Python:myscript'.  Is
>this the way it's supposed to behave?  If so, why?

Two things:
- the path to a root directory needs to end with a colon
- a relative path has to start with a colon

If your ariginal paths are correct, os.path.join() works like a charm:

>>> os.path.join('cwalker:', ':Macintosh HD:Devel:Python:myscript')
'cwalker:Macintosh HD:Devel:Python:myscript'

Just