Search code examples
python-3.xfilepath

How to handle file path in multiplatform way (both win/Unix)?


ROOT_DIR = os.path.abspath(os.curdir)

#create dir for files as it could be non-existent

directory = ROOT_DIR + CFG_FILE_RECPATH

Under win env CFG_FILE_RECPATH have to be like \\upload\ But under Ubuntu /upload/

For the moment I change the d limitter literal from '\' to '/' is it good enough?


Solution

  • You are looking for the os.path.join function.

    directory = os.path.join(ROOT_DIR, CFG_FILE_RECPATH)