Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python how to join cross platform paths

If I have a json directory structure that lists paths in mac format ()i.e. "/0000_test/video.mp4" and I want to join it with c:\\ the mac format, is there a way to do this?

So on windows the path would be returned as c:\\0000_test\video.mp4"

I have tried os.path.join to no avail

like image 774
Startec Avatar asked Jun 20 '26 05:06

Startec


1 Answers

You can use os.path.join and os.path.normpath

>>> os.path.normpath(os.path.join('C:', '/0000_test/video.mp4'))
'C:\\0000_test\\video.mp4'

normpath will take care of normalizing the path in a platform specific manner.

like image 112
Cory Kramer Avatar answered Jun 22 '26 19:06

Cory Kramer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!