Behaviour of os.path.join

Terry Reedy tjreedy at udel.edu
Thu May 28 17:34:50 EDT 2020


On 5/28/2020 9:19 AM, Eryk Sun wrote:
> On 5/26/20, BlindAnagram <blindanagram at nowhere.com> wrote:
>>
>> But if I try to make the directory myself (as I tried first):
>>
>>    join(base, '..\\..\\', 'build', '\\')
>>
>> I obtain:
>>
>> 'C:\\'
>>
>> The documentation says that an absolute path in the parameter list for
>> join will discard all previous parameters but '\\' is not an absoute path!
> 
> First, to be clear, a rooted path in Windows is not absolute (*), but
> that's not relevant here. What happens is that joining a path is like
> issuing successive "cd" commands in the shell, and "cd \" takes you to
> the root path of the current drive. The implementation of
> ntpath.join() similarly tracks the current drive via
> ntpath.splitdrive() while joining components.

Ah.  cd only changes the cwd within a device. Changing the active device 
is done otherwise.  In Command Prompt

C:\Users\Terry>f: # : required

F:\>c:

C:\Users\Terry>cd f:
F:\

C:\Users\Terry>cd f:/dev

C:\Users\Terry>f:

f:\dev>

-- 
Terry Jan Reedy



More information about the Python-list mailing list