Skip to main content
Clarified title
Link
Doresoom
  • 7.5k
  • 14
  • 49
  • 62

Python os.path.join() mangling absolute path in Windows

Source Link
Doresoom
  • 7.5k
  • 14
  • 49
  • 62

Python mangling absolute path in Windows

I'm new to Python and I'm trying to access a file with a full path represented by the following:

'X:/01 File Folder/MorePath/Data/Test/myfile.txt'

Every time I try to build the full string using os.path.join, it ends up slicing out everything between the drive letter and the second path string, like so:

import os
basePath = 'X:/01 File Folder/MorePath'
restofPath = '/Data/Test/myfile.txt'
fullPath = os.path.join(basePath,restofPath)

gives me:

'X:/Data/Test/myfile.txt'

as the fullPath name.

Can anyone tell me what I'm doing wrong? Does it have something to do with the digits near the beginning of the base path name?