Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert Windows filepath to Ubuntu on Windows filepath
from pathlib import Path
def win2lin(rpath: r"C:\Users..."):
path = rpath.replace("\\", "/").replace(":/", "/")
drive = path[0]
path = Path("/mnt/") / Path(drive.lower() + path[1:])
return path
### Example:
# >>> win2lin(r"C:\Users\myuser\Documents")
# PosixPath('/mnt/c/Users/myuser/Documents')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.