Skip C native functions

This commit is contained in:
hyugogirubato
2024-06-22 18:07:30 +02:00
parent 36d5f0db6a
commit c9d452e7c6
3 changed files with 90 additions and 3 deletions
+23
View File
@@ -0,0 +1,23 @@
import re
from typing import Union
from pathlib import Path
def sanitize(path: Union[Path, str]) -> Path:
if isinstance(path, str):
path = Path(path)
paths = [path.name, *[p.name for p in path.parents if p.name]][::-1]
for i, p in enumerate(paths):
p = p.replace('...', '').strip()
p = re.sub(r'[<>:"/|?*\x00-\x1F]', '_', p)
paths[i] = p
return Path().joinpath(*paths)
if __name__ == '__main__':
path = Path() / 'hello rgtgr/sdg'
print(path)
path = sanitize(path)
print(path)