Skip to content

Commit 35d8328

Browse files
committed
file_utils: Add generic file sanitize function
1 parent 2a527fc commit 35d8328

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

ofunctions/file_utils/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
__copyright__ = "Copyright (C) 2017-2024 Orsiris de Jong"
1919
__description__ = "File/dir/permissions/time handling"
2020
__licence__ = "BSD 3 Clause"
21-
__version__ = "1.2.4"
22-
__build__ = "2022110601"
21+
__version__ = "1.2.5"
22+
__build__ = "2026031601"
2323
__compat__ = "python2.7+"
2424

2525
import json
@@ -871,3 +871,10 @@ def get_writable_random_file(
871871
),
872872
)
873873
return None
874+
875+
876+
def sanitize_filename(file: str) -> str:
877+
"""
878+
Sanitizes a filename so we're sure it can be used on all platforms
879+
"""
880+
return "".join(x if x.isalnum() else "_" for x in file)

0 commit comments

Comments
 (0)