cowlinator cowlinator - 2 years ago 143
Python Question

Construct a filepath for a different operating system in Python

How can I use python to construct a path intended for a different operating system than the one the script is running on?

E.g. I am running a script on Linux in which I want to construct the Windows path

winPath = os.path.join(winRoot, dir, subdir) #doesn't work when script is run on linux

Answer Source

Check this doc page

Import the ntpath module to generate windows paths.

winPath = os.join.path(winRoot, dir, subdir)


winPath = ntpath.join(winRoot, dir, subdir)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download