Skip to content

Instantly share code, notes, and snippets.

@roachsinai
Created December 4, 2023 14:16
Show Gist options
  • Save roachsinai/89c556d973c04a8bc092bc39b65b01f0 to your computer and use it in GitHub Desktop.
Save roachsinai/89c556d973c04a8bc092bc39b65b01f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import subprocess
from pathlib import Path
result = subprocess.run(sys.argv[1:], capture_output=True)
result.stderr = result.stderr.lower()
# 深度优先搜索 + 剪枝
def dps(prefix, win_path):
if not win_path:
return prefix
for p in reversed(sorted(Path(prefix).iterdir())):
dir_name = p.name.lower()
try:
if p.is_dir() and dir_name == win_path[:len(dir_name)]:
res = dps(f"{prefix}{p.name}/", win_path[len(dir_name):])
if res:
return res
except PermissionError:
pass
# if windows path delimiter using slash
if (result.stderr == b''):
prefix = result.stdout.decode('utf-8')
else:
win_path = result.stderr[11:-1].decode('utf-8')
label = chr(result.stderr[9])
idx = 0
prefix = f"/mnt/{label}/"
prefix = dps(prefix, win_path)
print(prefix, end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment