Created
February 8, 2024 11:37
-
-
Save nezuppo/3298a8dacfb6a8afc21f4a3abd2adede to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
from pathlib import ( | |
PurePosixPath, | |
PureWindowsPath, | |
) | |
def get_wslpath(winpath): | |
purewinpath = PureWindowsPath(winpath) | |
winpath_parts = purewinpath.parts | |
if winpath_parts[0].endswith(':\\'): | |
assert len(winpath_parts[0]) == 3, winpath_parts | |
assert winpath_parts[0][0].isalpha(), winpath_parts | |
pureposixpath = PurePosixPath('/mnt', winpath_parts[0][0].lower(), *winpath_parts[1:]) | |
else: | |
pureposixpath = PurePosixPath(*winpath_parts) | |
wslpath = str(pureposixpath) | |
return wslpath | |
if __name__ == '__main__': | |
# example | |
winpath = 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' | |
wslpath = get_wslpath(winpath) | |
print() | |
print('winpath:', winpath) | |
print('wslpath:', wslpath) | |
from subprocess import check_call | |
cmd = ['wsl.exe', 'ls', '-la', wslpath] | |
print() | |
check_call(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment