linuxize-path.py
1#!/usr/bin/env python3
2
3import sys
4import os
5import re
6
7args = sys.argv
8SCRIPT_NAME = os.path.basename(__file__)
9
10if len(args) != 2:
11 print("lp (linuxize path). made by cookie.")
12 print(f"usage: {SCRIPT_NAME} WINDOWS_FILE_PATH")
13 exit(1 if len(args)>2 else 0)
14
15win_path = args[1]
16linux_path = win_path.replace("\\", "/")
17
18# prepend with "/mnt/{drive_letter}" if is absolute path
19m = re.match(r"[A-Z]:", linux_path)
20if m:
21 drive_letter = m.group(0)[0].lower()
22 linux_path = re.sub(r"[A-Z]:", f"/mnt/{drive_letter}", linux_path)
23
24print(linux_path)