Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Created February 26, 2019 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasaarholt/d6578ed9b8de7710f074e90047188f6b to your computer and use it in GitHub Desktop.
Save thomasaarholt/d6578ed9b8de7710f074e90047188f6b to your computer and use it in GitHub Desktop.
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