Created
          February 26, 2019 08:54 
        
      - 
      
 - 
        
Save thomasaarholt/d6578ed9b8de7710f074e90047188f6b to your computer and use it in GitHub Desktop.  
    Convert Windows filepath to Ubuntu on Windows filepath
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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